Monday 8 April 2013

SAP HANA SQL FUNCTIONS


Functions

Functions are used to return information from the database. They are allowed anywhere an 
expression is allowed. Functions use the same syntax conventions used by SQL statements.
Data type conversion functions

Data type conversion functions are used to convert arguments from one data type to another, or 
to test whether they can be converted.

CAST Function
Syntax:
CAST(expr AS data_type)
Description:
Returns the value of an expression converted to a supplied data type. 
Parameters:
  expression   - The expression to be converted.
  data type   The target data type.
BIGINT | BINARY | BLOB | CHAR | CLOB | DATE | DECIMAL | DOUBLE | NCHAR | 
NCLOB | REAL | TIME | TIMESTAMP 
Example:
SELECT TOP 1 CAST(7 AS CHAR(10)) "cast" FROM users;
Retrieves:
cast
7
TO_BIGINT Function
Syntax:
TO_BIGINT(expr)
Description:
Converts the expr of a data type into a value of bigint data type.
Example:
SELECT  TOP 1 TO_BIGINT('10') "to bigint" FROM users;
Retrieves:
to bigint
10
TO_BINARY Function
Syntax:
TO_BINARY(expr)
Description:
Converts the expr of a data type into a value of binary string type. 
SAP In-Memory Database SQL Reference Manual     
10
Example:
SELECT TOP 1 TO_BINARY('abcde') "to binary" FROM users;
Retrieves:
to binary
6162636465
TO_BLOB Function
Syntax:
TO_BLOB(expr)
Description:
Converts the expr of a data type into a value of blob type. expr must be a binary string. 
Example:
SELECT TOP 1 TO_BLOB(TO_BINARY('abcde')) "to blob" FROM users;
Retrieves:
to blob
abcde
TO_CHAR Function
Syntax:
TO_CHAR(expr [,format])
Description:
Converts the expr of a data type into a value of character data type.
Example:
SELECT TOP 1 TO_CHAR(TO_DATE('2009-12-31'), 'YYYY/MM/DD') "to char" FROM users;
Retrieves:
to char
2009/12/31
TO_CLOB Function
Syntax:
TO_CLOB(expr)
Description:
Converts the expr of a data type into a value of CLOB data type.
Example:
SELECT TOP 1 TO_CLOB ('TO_CLOB converts an expression into a value of CLOB data type') "to clob"
FROM users;
Retrieves:
to clob
TO_CLOB converts an expression into a value of CLOB data type
TO_DATE Function
Syntax:
TO_DATE(expr [, format])
Description: 
SAP In-Memory Database SQL Reference Manual     
11
Converts the expr of a data type into a value of DATE data type.
Example:
SELECT TOP 1  TO_DATE('2010-01-12', 'YYYY-MM-DD') "to date" FROM users;
Retrieves:
to date
2010-01-12
TO_DATS Function
Syntax:
TO_DATS(expr)
Description:
Converts the expr of a data type into a value of ABAP DATE data type.
Example:
SELECT TOP 1 TO_DATS('2010-01-12') "abap date" FROM users;
Retrieves:
abap date
20100112
TO_DECIMAL Function
Syntax:
TO_DECIMAL(expr[, precision, scale])
Description:
Converts the expr of a data type into a value of DECIMAL(precision, scale) data type.
Example:
SELECT TOP 1 TO_DECIMAL(7654321.89, 9, 2) "to decimal" FROM users;
Retrieves:
to decimal
7654321.89
TO_DOUBLE Function
Syntax:
TO_DOUBLE(expr)
Description:
Converts the expr of a data type into a value of DOUBLE (double precision) data type.
Example:
SELECT TOP 1 3*TO_DOUBLE ('15.12') "to double" FROM users;
Retrieves:
to double
45.36 

Saturday 9 March 2013

SAP HANA CATLOG TABLE NAMES


  SAIRPORT – master data table with name and time zone information for airports
  SAPLANE – master data table with information about plane types, e. g. number of seats, 
weight, tank capacity, and operating speed
  SBOOK – fact table containing all flight bookings and their details like date of flight, flight 
number, price, customer ID, and ID of the travel agency that sold the ticket.
  SBUSPART – master data table with information about business partners
  SCARR – master data table with some airline information (name, currency, URL)
  SCURR – table with currency conversion factors
  SCURX – per-currency number of decimals used to display currency values
  SCUSTOM – master data table containing information about passengers
  SDESSERT – master data table with information about the desserts available during flights
  SFLIGHT -  master data table containing per-flight information, e. g. date, price, plane type, 
seats
  SMACOURSE – master data table with information about the main courses available during 
flights
  SMEAL – master data table with information about the meals available during flights
  SMEALT – master data table with information about the meals in various languages
  SMENU – master data table with information about the available combinations of meals
  SSTARTER – master data table with information about the main courses available during 
flights
  STICKET – fact table which contains information about the tickets issued at the airports
  STRAVELAG – master data table containing information about travel agencies

SAP HANA MODELING VIEWS


SAP HANA Modeling Views

Before we continue to discuss how to model in SAP HANA, first it is important to understand each of 
the differing SAP HANA modeling view types and their capabilities.

Attribute Views

Attribute views are used to give master data tables context. This context is provided by text tables 
which give meaning to the master data. For example, if our fact table or analytic view only contains 
some numeric ID for each car dealer then we can link in information about each dealer using an 
attribute view. We could then display the dealers’ names and addresses instead of their IDs thus 
providing the context for the master data table. 
Attribute views are used to select a subset of columns and rows from a data table. As it is of little use 
to sum up attributes from master data tables there is no need to define measures or aggregates for 
attribute views.

You can also use attribute views to join master data tables to each other, e. g. joining “Plant” to 
“Material”.

Analytic Views -----

Analytic views are used to build a data foundation based on transactional tables. You can create a 
selection of measures (sometimes referred to as key figures), add attributes and join attribute views.
Analytic views leverage the computing power of SAP HANA to calculate aggregate data, e. g. the 
number of sold cars per country, or the maximum power consumption per day. They are defined on 
at least one fact table, i. e. a table which contains e. g. one row per sold car or one row per power 
meter reading, or more generally speaking, some form of business transaction records. Fact tables 
can be joined to allow access to more detailed data using a single analytic view. Analytic views can be 
defined on a single table, or joined tables.
Analytic views can contain two types of attributes (or columns), so-called measures and normal 
attributes. Measures are attributes for which an aggregation must be defined. If analytic views are 
used in SQL statements (see below) then the measures have to be aggregated e. g. using the SQL 
functions SUM(<column name>), MIN(<column name>), or MAX(<column name>). Normal attributes 
can be handled as regular columns. For them there is no need to be aggregated


Calculation Views

Calculation views are used to provide composites of other views. They are essentially a view which is 
based on the result of an SQLScript. These scripts can join or union two or more data flows or invoke 
built in Calculation engine or generic SQL functions.
Calculation views are defined as either graphical views or scripted views depending on how they are 
created. They can be used in the same way as analytic views, however, in contrast to analytic views it 
is possible to join several fact tables in a calculation view. Calculation views always have at least one 
measure. 
Graphical views can be modeled using the graphical modeling features of the SAP HANA Information 
Modeler. Scripted views are created as sequences of SQLScript statements. In essence they are 
SQLScript procedures with certain propertie







Saturday 2 March 2013

SAP HANA ----DATA MODELING OVERVIEW




 http://www.erphowtos.com/templates/rt_solarsentinel_j15/images/arrow.pngSAP HANA - Overview and Architecture


HANA is High-Performance Analytic Appliance is an in memory appliance for SAP systems. Below are the notes/highlights of HANA for the webinar I attended recently.


Overview and Architecture of HANA
  • What is HANA ? - In memory computing engine
  • In memory computing studio as a fronend for modleing and administration. 
  • HANA is connected ERP systems, Frontend modeling studio can be used for load control and replication server management 
  • Two types of Relational Data stores in HANA : Row Store, Column Store 
  • SAP BOBJ tools can directly report HANA 
  • Data from HANA can also be used in MS Excel
  • Row Store – Traditional Relational Database , the difference is that all the rows are in memory in HANA where as they are stored in a hard drive in traditional databases. 
  • Column Store – The data is stored in columns like in SAP BWA 
  • Persistency Layer: In memory is great by it is volatile and data can be lost with power outage or hardware failures. To avoid this HANA has a Persistencey Layer component which makes sure that all the data in memory is also store in a hard drive which is not volatile 
  • Session Management: This component takes care of logon services 
  • Two processing engines – Well, data is in memory which is good but How do I extract/report on the data? HANA has two processing engines one is based on SQL which accepst SQL queres and the other one is based on MDX .  
  • HANA Supports Sybase Replication Server – Sybase Replication Server can be used for realtime synchronization of data between ERP and HANA 
Modeling Studio

Using Modeling Studio you can,
  • Specify which tables are stored in HANA, first part is to get the meta data and then schedule data replication jobs 
  • Manage Data Services to load the data from SAP BW and other 3rd party systems. 
  • Manage connections to ERP instances, current release does not support connecting to several ERP instances 
  • Use Dataservices to for the modeling 
  • Do modeling in HANA itself (This is independent of Dataservices).
  • You can also do modeling can also be done in Business Objects Universes which is nothing but joining fact and dimensional tables.
Reporting
  • Client tools can access HANA directly, Like MS EXCEL, SAP BI 4.0 Reporting tools, Dashboard Design Tool (Xcelsius)etc can also access HANA directly. 
  • Third party reporting tools can leverage ODBC, JDBC and ODBO (for MDX requests) drivers in HANA for reporint. 
  • HANA supports BICS interface
Request Processing and Execution Control
  •  SQL Script, MDX statemenst are passed to calculation modles. Optiomizer which is included in caluculation engine optimizes for better performance.
  •  Calc Engine :
    •  Modeler can define data sources as inputs and different operations (join, aggreagation, projection) on top of them for data manipulation
    •  The calc engine will break up a model into sub processes for optimized performance on cost based.
    •  System will use maximum resources to achive max through put
  •  Planning Enigne : Will be included in next release. Will include planning functions like distribute and copy functions.

ROW Store
  • One of the relational engines to store data in row format.
    • Pure in-memory store (Future versions will also have an option of disk based store)
    • In memory object store (in future) for live cache functionality
    • Transactions Version Memory is the heart of row store
  • Row store architecture
    • Write operation mainly go into "Transactional Version Memory"
    • INSERT also writes to persisted segment
    • Moves visible version from memory to persisted segment
    • Clears outdated record versions from Transactional Version memory
    • Row Store tables have a primary index
    • Row ID maps to primary key
    • Secondary indexes can be created
    • Row ID contains the segment and the page for the record
    • Indexes in row store only exist in memory
    • Index definition stored with table meta
Column Store
  • Improves read functionality significantly, also improves write functionality
  • Highly compressed data
  • No real files, virtual files
  • Optimizer and Executer – Handles queries and execution plan
  • Delta data for fast write
  • Asynchronous delta merge
  • Consistent view Manager
  • Main store compressed and read optimized – Data is read from Main Store
  • Delta Store – Write optimized – for write operations.
  • Asynchronous merge move the data from delta store to main store
  • Compression by create dictionary and applying further compression methods
  • Even during the merge operation, the columnar table will still be available for read and write operations. To fulfil this, a second delta and main storage are used internally
  • Merge operation can also be triggered manually with an SQL command
Persistence Layer
  • Peristence Layer is needed as Main memory is volatile
  • Provides Backup and Restore functionality
  • One Persistency Layer takes care of both row and column stores
  • Regular Save Points
  • Logs capturing DB transactions since last save point
  • Actions during system restart
    • Last savepoint must be restored plus undo logs must be read and uncommitted atransactions saved with last save point and apply redo logs
    • Complete content of row store is loaded into memory during start procees
    • Flags can be set for column store to specify which tables are loaded during system restart
Modeling
  • Modeling only possible for Column tables
  • Information Modeler only works for column tables
  • Replication servers create tables in column store per default
  • Data Services creates tables in column store per default
  • SQL to create column table: Create COLUMN TABLE
  • Store can changed with ALTER TABLE
  • System tables are create where they fit best
  • Schema SYS -> chaces, administrative table of engine
  • Tables from stastics server

In-Memory Computing Studio
  • Build with java based eclipse
  • Navigator to access different HANA systems on left, Quick Launch View at the middle and Properties view at the bottom.
  • Information Modler Features:
    • Database views
    • Choice to publish anc consume at 4 levels of modeling
      • Attribute view, analytic view ...
    • Physical tables and Information Models
    • Import/export models, data source shcemas, mass and selective load
    • Landscapes
  • The models are just virtual definitions they don't store actual data
  • Analytic Views are like cube model where Transaction Data is connected to attribute view
  • Calc View – With custom functions and calculations
  • Modeling Process Flow
    • Import Source System Metadata
    • Create Information Models
    • Consume using BICS, SQL or MDX
  • Infromation Modeler Terminology
    • Attributes – Characteristics
    • Measure – Key Figures
    • Attribute Views – Dimentions
    • Analytic Views – Cubes
    • Calculation Views – Similar to Virtual provider concept in BW
    • Hierarcheis
      • Leveled – based on multiple attributes
      • Parent-child hierarchy
    • Analytic Privilege – Security Object
  • Navigation View
    • HANA instance -> Hana srver name and instance numbe -> user database schema -> views functions and tables
    • Information Modles – Attribute, Analytic, Calculation Views and Analytic Previlege
  • Attribute View :
    • Attributes add context to data
    • Attributes are modeled using attributes views
    • Can be regarded as Master Data Tables
    • Can be linked to fact tables in Analytical Views
    • A measure e.g. weight can be defined as an attributes
    • Table Joins and properties
      • Leftouter,rightouter, full outer or text table
      • Cardinality 1:1, N:1, 1:N
      • Language Column
    • Content Views and Functions will be shipped with HANA
  • Analytics View:
    • Similar to Cube
    • Analytic Views does not sotre any data. The data is stored in column store table or view based on Analytical View structure
    • Attributes and Measures – Like key figures
  • Data Preive – Similar to listcube functionality
  • Calculation View:
    • Define table outpu Structure
    • Write SQL statement
      • Ensure the selected fields correspons to previously defined output structes
    • SQL Scripts unlike SQL procedure can't change any data they are read only

SAP HANA ---JOINS


SAP HANA --IN MEMORY STUDIO FEATURES


HANA Studio- Features:
Modeling
o  Information Models
Information models are used to create multiple views of transactional data that
can be used for analytical purposes.
o  Attribute View, Analytic View, Calculation View , Calculation View enhanced with
Analytical View
Data Preview
o  Physical tables
o  Information Models
Import/Export
o  Models
o  Data Source schemas (metadata) – mass and selectiveload
o  Landscapes
Data Provisioning (both initial load and replication)
Analytic Privileges / Security
Troubleshooting / Trace / Logs
Important HANA Studio Terminologies:
Data
o  Attributes – descriptive data (known as Characteristics SAP BW terminology)
Calculated Attributes
o  Measures – data that can be quantified and calculated (known as key figures in SAP BW)
Calculated Measures & Restricted Measures
Views
o  Attribute Views – i.e. DIMENSIONS
o  Analytic Views – i.e. CUBES
o  Calculation Views – similar to virtual provider with services concept in BW
Graphical
Script (SQL Script, CE Functions)
Procedures
o  Functions – re-usable functionality
Analytic Privilege – security object
o  Analytic PrivilegS

SAP HANA-- IN MEMORY APPLIANCE