0% found this document useful (0 votes)
60 views26 pages

20 Data Models Stored Procedures

20 Data Models Stored Procedures

Uploaded by

SARGURU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views26 pages

20 Data Models Stored Procedures

20 Data Models Stored Procedures

Uploaded by

SARGURU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Data Modeling & Stored

Procedures in SAP HANA

SAP Startup Focus


SAP HANA 1.0, SPS 09, H1, 2015

www.saphana.com/startupfocus
Agenda
Overview & Introduction
Modeling:
Attributes
Analytics
Complex Modeling
Stored Procedures:
SQLScript
CE Functions
Overview: Creating an Application

OData over HTTP

SQL over xDBC

access control
data model
(DB)

2015 SAP AG or an SAP affiliate company. All rights reserved. 3


Agenda
Overview & Introduction
Modeling:
Attributes
Analytics
Complex Modeling
Stored Procedures:
SQLScript
CE Functions
Modeling for HANA: Three Types of Views

Step1: (Attribute View)


Separate Master Data Modeling from Fact data
Build the needed master data objects as Attribute Views
Join text tables to master data tables
If required: join master data tables to each other (e.g. join Plant to
Material)

Step 2: (Analytical View)


Create Cube-like view by joining attributes view to Fact data
Build a Data Foundation based on transactional table
Selection of Measures (key figures) ...
Add attributes (docking points for joining attribute
views)
Join attribute views to data foundation
Looks a bit like a star schema

2015 SAP AG or an SAP affiliate company. All rights reserved. 5


Modeling for HANA: Three Types of Views

Step 3: Calculation View for more complex models


Composite view of other views (tables, re-use join, olap views)
Consists of a Graphical & Script based editor

2015 SAP AG or an SAP affiliate company. All rights reserved. 6


Attribute Views

What is an Attribute View?


Attributes add context to data
Can be regarded as Master Data
objects
Handling of multi-language master
data texts
Can be re-used as dimensions in
Analytical Views

2015 SAP AG or an SAP affiliate company. All rights reserved. 7


Attribute View:
Define join properties

Table Joins and Properties

Join Types
Referential
Inner
LeftOuter
rightOuter
TextJoin
Cardinality
1:1
N:1
1:N
Language Column (for text join)
Note: the direction in which you
draw the join matters (left table first)

2015 SAP AG or an SAP affiliate company. All rights reserved. 8


Attribute View:
Output field selection and filters

Select Attributes to show up in view

The output structure of the view must be


explicitly defined:

At least one key attribute is required


Any number of non-key attributes may be
defined

Define static filter values: Column Store Activate


Can be based on any table column
Column does not need to be selected for
output ([key] attribute)

2015 SAP AG or an SAP affiliate company. All rights reserved. 9


Attribute View:
Preview the view

Data Preview

2015 SAP AG or an SAP affiliate company. All rights reserved. 10


Analytic View

An Analytic View can be regarded as a


cube
Multidimensional reporting model
Fact table (data foundation) joined
against modelled dimensions
(attribute views)
Analytic Views do not store data
Data is read from the joined database
tables
Joins and calculated measures are
evaluated at run time

2015 SAP AG or an SAP affiliate company. All rights reserved. 11


Analytic View Editor
Tab Data Foundation Create the data foundation (fact table)
(Optional: join data base tables)
Select attributes and measures from table(s) this defines the data foundation
(Optional: create calculated and restricted measures)
Tab Logical View Join Attribute Views to the data foundation
This is where you can drag attribute views into the editor

Data Foundation Logical View

2015 SAP AG or an SAP affiliate company. All rights reserved. 12


Analytic View
Join Attribute Views to Data Foundation

Join the attribute view to a an attribute of the data foundation


Typically one would include all key attributes of the attribute view in the join definition
Default join type is the referential join (an optimized inner join)

Non-key fields of attribute view are


implicitly added to the analytic view
Navigation attributes

2015 SAP AG or an SAP affiliate company. All rights reserved. 13


Analytic View
Create an Executable Version of the View

Save the view


This saves the information model, i.e. the metadata of
the view that has just been defined.
This information model itself is not visible to reporting
tools
Activate the view
Right-click view and choose Activate from context
menu
This creates a database view in schema _SYS_BIC (a Column Store
so-called column view)
Name of the column view:
_SYS_BIC.<PACKAGE>/<VIEW_NAME>
This column view can be accessed from reporting tools

2015 SAP AG or an SAP affiliate company. All rights reserved. 14


Analytic View
Run-time object: column view

The column view can be accessed from reports


Exposed like regular views via SQL/MDX interfaces
Reports

Column Store

Activate

2015 SAP AG or an SAP affiliate company. All rights reserved. 15


Two Types of Calculation Views

Composite views, re-uses Analytical and Attribute views


SQL / SQL Script / Custom Functions

Graphical Calculation View SQL Script Calculation View

Union Analytical View

Projection

Projection

Analytical View

Union

2015 SAP AG or an SAP affiliate company. All rights reserved. 16


Calculation View
Graphical

No SQL / SQL Script coding needed


Can consume other Analytical Views, Attribute Views, Calculation Views & tables
Union, Join, Projection nodes provided, enhance existing view functionality

Attribute View

Analytical View

Calculation View

UNION UNION
Combining multiple Analytical Views 2.. N (Input Sources)

Use Union with Constant values when working with Multiple (2..N) Analytical Views / fact tables

2015 SAP AG or an SAP affiliate company. All rights reserved. 17


Calculation View
SQLScript (Script-based)

SQL or SQLScript required to create Script based Calculation Views


Write SQL Select statements against existing raw tables or Column Stores (preferred)
Define output structure, activation creates column store based on Script Output

Analytical View

Projection

Union

2015 SAP AG or an SAP affiliate company. All rights reserved. 18


Agenda
Overview & Introduction
Modeling:
Attributes
Analytics
Complex Modeling
Stored Procedures:
SQLScript
CE Functions
SQLScript
What is it?

SQLScript is an extension of ANSI Standard SQL that provides an interface for


applications to access SAP HANA.
A functional extension that enables the definition of (side-effect free)
functions which can be used to express and encapsulate complex data flows
A data type extension that enables the definition of types without
corresponding tables

It is a language for creating stored procedures in HANA:


Declarative Logic including SELECT queries and Built-In Calculation Engine
functions
Orchestration Logic including Data Definition Language (DDL), Data
Manipulation Language (DML), assignment, imperative logic

2015 SAP AG or an SAP affiliate company. All rights reserved. 20


SQLScript
What are its Advantages?

Compared to plain SQL queries, SQLScript has the following advantages:


Functions can return multiple results, while a SQL query returns only one
result set.
Complex functions can be broken down into smaller functions. Enables
modular programming, reuse and a better understandability by functional
abstraction. For structuring complex queries, standard SQL only allows the
definition of SQL views. However, SQL views have no parameters.
SQLScript supports local variables for intermediate results with implicitly
defined types. With standard SQL, it would be required to define globally
visible views even for intermediate steps.
SQLScript has control logic such as if/else that is not available in SQL
Increased performance via parallel processing

2015 SAP AG or an SAP affiliate company. All rights reserved. 21


SQLScript
Where to use?

SQLScript is the major programming language in DB layer and there are two ways
to implement:
SQLScript based calculation views
Stored procedures

SQLScript is also the interface to invoke some other programming options in SAP
HANA:
R Integration
BFL(Business Function Library)

2015 SAP AG or an SAP affiliate company. All rights reserved. 22


SQLScript Table Type

Table Type in Stored Procedures

Table Type in Calculation Views

Allows for the definition of new Table Types


Similar to a database table but do not have an
instance
Used to define function parameters
Created when the Calculation View is activated

2015 SAP AG or an SAP affiliate company. All rights reserved. 23


SQLScript
Code example

BEGIN
...
Products
-- Query 1
product_ids = select "ProductId", "Category", "DescId"
from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::products"
where "Category" = 'Notebooks'
or "Category" = 'PC';

-- Query 2 Q1
product_texts = select "ProductId", "Category", "DescId", "Text"
from :product_ids as prod_ids
inner join "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::texts"
as texts on prod_ids."DescId" = texts."TextId";

-- Query 3
out_notebook_count = select count(*) as cnt from
:product_texts where "Category" = 'Notebooks'; Q2
-- Query 4
out_pc_count = select count(*) as cnt from
:product_texts where "Category" = 'PC';

...
Q3 Q4
END;

Notebooks PCs

2015 SAP AG or an SAP affiliate company. All rights reserved. 24


SQLScript
Built in function code example
Built in functions should be used exclusively where possible
Calculation Engine functions should not be mixed with standard SQL statements
Queries can be well optimized and parallelized by the engine

bp_addresses =
select a."PartnerId", a."PartnerRole", a."EmailAddress", a."CompanyName",
a."AddressId", b."City", b."PostalCode", b."Street"
from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::businessPartner" as a
inner join "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::addresses" as b
on a."AddressId" = b."AddressId" where a."PartnerRole" = :partnerrole;
SQL

lt_bp = CE_COLUMN_TABLE("SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::businessPartner",
["PartnerId", "PartnerRole", "EmailAddress", "CompanyName", "AddressId" ]);

lt_bp_proj = CE_PROJECTION(:lt_bp, ["PartnerId", "PartnerRole", "EmailAddress" , "CompanyName",


"AddressId" ], '"PartnerRole" = :partnerrole' );

lt_address = CE_COLUMN_TABLE("SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::addresses", CE
["AddressId", "City", "PostalCode", "Street"]);

bp_addresses = CE_JOIN(:lt_bp_proj, :lt_address, ["AddressId"],


["PartnerId", "PartnerRole", "EmailAddress", "CompanyName", Functions
"AddressId", "City", "PostalCode", "Street"]);

2015 SAP AG or an SAP affiliate company. All rights reserved. 25


Thank you.
Contact Information:

SAP Startup Focus for SAP HANA


[email protected]

You might also like