Nothing Special   »   [go: up one dir, main page]

SAP HANA Development Basics PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 159

SAP HANA Development

Basics
December, 2017 Confidential
Agenda

• SAP HANA Architecture • SQLScript and Procedures

• SAP HANA Studio Overview • Export and Import

• Data Provisioning Overview and SAP • HANA Performance


Landscape Transformation (SLT)
• User Management & Security
• SAP HANA Overview
• A Data Consumption example using Microsoft
• SAP HANA Modeling: Working with Tables Excel

• SAP HANA Modeling: Calculation Views

• Variables and Input Parameters

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 2


SAP HANA Architecture
Advances in Hardware made SAP HANA possible

Dramatically improved hardware economics made SAP HANA possible.


Understanding them is important to understand HANA’s performance characteristics.

Multi-core architecture
 8 CPUs x (8-16) cores per blade
 Parallel scaling with many blades
 64-bit address space – 4 TB in current server boards
 Dramatic decline in price/performance

https://global.sap.com/community/ebook/2014-09-02-hana-hardware/enEN/index.html

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 4


Overcoming old constraints with SAP HANA

Three-tier application architecture resulted


from several constraints:
 Data does not fit into server memory. Application Server
 Disk I/O is a performance bottleneck.
 The network is a performance bottleneck. CPU

 CPUs have one core, with no true parallelism. Core


…
CPU Cache
Some of these constraints have changed: Now
 Now data transfer between memory and CPU is Main Memory
the most critical performance bottleneck. Past
Disk

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 5


Advances in Software made SAP HANA possible

Row and Column Store

Compression

Partitioning

Avoiding Aggregate Tables

Insert Only on Delta +


+ ++

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 7


What about Data Modifications?

UPDATE ORDER
Technically, SAP HANA is an SET Sales = 1050
“insert-only” DBMS: WHERE ORDER = 457
 Speeds up data modifications Column Column Column
 Applies modifications to delta store first Order Product Sales
 Less optimized columnar store Value Value Value

Delta Store
1 456 1 corn 1 1000
2 457 2 wheat 2 1050
3 458 3 corn 3 600
4 459 4 rice 4 800
Applications can still insert,
update, and delete data.

Main Store
Value Value Value
… … … … … …
102 457 102 wheat 102 900
… … … … … …

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 8


Delta Store is merged with Main Store as required

Before delta merge operation: Write

 Delta store grows Main Delta


Store Store

During delta merge operation: Read


 Read/write access still works on old Merge Operation Write
stores and new delta store
Main New Delta New
Store Main Store Delta
After delta merge operation:
Read
 Data optimized for fast access again
Write

New New
Main Delta

Read

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 9


Expectations around SAP HANA
SAP HANA Architecture

3600x 460B 21%


Faster reporting Data records analyzed in Average increase
speed less than a second in revenue

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 12


Implications for developers

In-memory computing imperative:


 Avoid movement of large data volume.
 Calculate first, then move results.

Today:
Data-intense
Application Layer
computations in
application layer

SAP HANA:
Data Layer Delegate
data-intense
operations to
data layer

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 13


SAP HANA in the Cloud

• SAP HANA is also available in the Cloud


• You can use SAP HANA side-by-side as standalone appliance, or as SAP
Business Suite on SAP HANA
• SAP HANA One is available on subscription basis
• https://cloudplatform.sap.com/

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 14


Exercise: SAP HANA Architecture

There are no exercises for this Unit

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 15


SAP HANA Studio Overview
The SAP HANA Studio at a glance

• The SAP HANA Studio provides an environment for modeling, development,


administration, and data provisioning.
• The SAP HANA Studio is a Java based application that runs on the Eclipse Platform and
enables developers and modelers to create models and stored procedures, manipulate
tables and issue queries on top of SAP HANA.
• Modelers can create Information Models based on the raw tables.
• Developers can develop application logic on top of SAP HANA using SQLScript, a
collection of extensions to SQL that pushes down data intensive logic into the
database. They can also create UI5 JavaScript code to accompany server based
procedures.
• You can also monitor and configure some aspects of the data provisioning (replication,
extraction) and debug procedures, create and view traces, and monitor the system status.
• Available at: https://tools.hana.ondemand.com/#hanatools

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 17


Starting the SAP HANA Studio

When you start the SAP


HANA Studio you can
decide on several
perspectives, as
predefined Layouts for
different roles. Users can
choose their preferred
perspective according to
their role.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 18


First steps with the SAP HANA Studio

• Developers will mostly work with the SAP HANA Development or Modeler perspective (you need
to switch to it manually the first time)
• The Administration console is useful to manipulate the SAP HANA data dictionary, manage
schemas, import/export data, perform interactive DB queries

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 19


Adding Systems (1)

How to add an SAP HANA System:

Right-click on the Systems panel:

Click on Add System

User names for each


SAP HANA system
1
SAP HANA
System names

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 20


Adding Systems (2)

• Enter Host Name and Instance Number and click on Next

• Enter User Name and Password and click on Finish

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 21


Adding Users: Changing Passwords

How do I change my password?


• Double-click on your User under Security  Users, enter new password and press Deploy (F8).
• Then don’t forget to change your password also in the Systems panel (right click on the system,
and then select Properties, and in the Database User Logon, change the previously saved
password)

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 22


Adding Users: Authorizations at a glance

Authorizations, Roles and Privileges:


• Using the Users Folder under Security, you can assign roles and different kinds of privileges to
users
• Double-click on your User under Security  Users
• Example: You can enable users to create schemas for their own SAP HANA projects by adding the
System Privilege “Create Schema”

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 23


Working with the Catalog

The Catalog in the SAP HANA Studio


• It contains the data Tables for your SAP HANA project
• Catalog data is organized in Schemas
• Data tables can be loaded from different sources, for
example, they can be replicated from SAP ERP, they can be
imported from files, etc.
• You can also create new tables with the SAP HANA Studio
• Under the Catalog you can also find Column Views (system
internal representations), Procedures and Views. However,
in most cases, Views and Procedures will be rather created
as Content (more details about the Content will be explained
in further lessons).

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 24


Working with Schemas

What are Schemas?


• They are separate name spaces for the different SAP HANA
catalog objects, for example, for replicated tables from SAP
ERP
• You can create different Schemas for your different purposes

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 25


A glimpse into the Development perspective

The SAP HANA Development Perspective:


• You can use the Development perspective to develop end-to-
end applications on top of SAP HANA
• You can create services, read/write procedures, Javascript
and UI5 objects, design time objects for tables, roles, etc.
• Debugging functionality is also available
• It contains a full development environment incl. SAP HANA
Repositories

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 26


Delivery Units to transport Content Packages

You can use the Quick launch to create Delivery Units:


• In this way you can transport your Content Packages (design time objects such as,
e.g. Column Views, Procedures, etc.) from one SAP HANA System to the other

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 27


Validation Rules

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 28


Active/Inactive Artifacts – Version History

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 29


Where used

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 30


Exercise: Get familiar with the SAP HANA Studio

The exercise for this Lesson is Exercise 1-1 in the “Student Exercise
Manual”.

You have 10 minutes for the Exercise

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 31


Data Provisioning Overview
and SAP Landscape
Transformation (SLT)
Different methods of data replication

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 33


ETL Based data provisioning: DataServices

BW
DSO

Openhub, RFC
Some Master
Data Tables ODBC HANA

DataServices
CRM
ABAP
Cluster tables Function calls
ODBC

Functions DS
Repo
DB2
Oracle (CVDS) ODBC

Tables, Views

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 34


Introducing the advantages of SAP LT Replication

▪ SAP LT uses trigger based approach. Trigger-based approach has no measureable performance
impact in source system
▪ It is based on the proven SLO technology (used for NearZeroDowntime, TDMS, etc.) used by
hundreds of customers with large DBs.

▪ It provides transformation and filtering capability


▪ It allows real-time (and scheduled) data replication, replicating only relevant data into HANA from
SAP and non-SAP source systems
▪ It is fully integrated with HANA modeler UI
▪ Replication from multiple source systems to one HANA system is allowed, also from one source
system to multiple HANA systems

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 35


SAP LT Key Building Blocks: SAP Source system

DB Trigger Write DB
Modules
Connection

Logging Read RFC Controler


Tables Modules Connection Modules
Application Tables

LT replication server does not have to be a separate


SAP system and can run on any SAP system with SAP
NetWeaver 7.02 ABAP stack (Kernel 7.20EXT)
Application Tables

Source system LT Replication Server SAP HANA Database

Efficient initialization of data Flexible and reliable replication Fast data replication via DB connect
replication based on DB trigger process, incl. data migration LT replication functionality is fully
and delta logging concept (as used for TDMS and SAP LT) integrated with SAP HANA Studio
(as with NearZero downtime approach)

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 36


COIL TDF Landscape Architecture

ECC + TDF S/4HANA + TDF

Terminal Server Terminal Server

ECC NW + TDF ECC NW + TDF

SLT HANA
HANA

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 37


Exercise: Data Provisioning overview and SAP LT

There are no exercises for this Unit

Demo
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 38
SAP HANA Overview
Content and Views in the SAP HANA Studio

• The SAP HANA Catalog contains run-time database


objects, such as tables, views, procedures, etc. and no
design-time objects

• Design-time objects and modeling tools are available in


the SAP HANA Content area in the Modeler perspective.
This allows modelers to design and model data Views out
of the “raw” tables.

• Using the SAP HANA Studio, users can define their


Views and start to model and “slice and dice” data.
Complex modeling may also take place somewhere else,
e.g. SAP BI or SAP BO.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 40


Working with Content

Content in the SAP HANA Studio:


• It contains design-time objects, e.g. analytic models, for
database objects, that is, nested content Packages for Packages
• Attribute Views
• Analytic Views
• Calculation Views
• It also contains Analytic privileges representing row-level
authorization filters evaluated dynamically during query
execution
• It also contains Procedures, i.e. is used to store Design-Time
objects
• SQLScript or
• L procedures
to express complex calculation or processing logic

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 41


Creating Content Packages

Right-click on Content and click on New  Package

Type your Package Name and click on OK

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 42


The 3 SAP HANA Modeling Views in a Nutshell

• Attribute View: Gives context to, and selects subset of columns and rows from data tables. Used
for all type of joins. In most cases used to model master data like entities (like Product, Location,
Business Partner)
• Analytic View: Used for calculation and aggregation (star-schema-like). Adds transactional tables
and measures (key figures), calculates aggregates (e.g. No. of Products sold per year), joins
Attribute Views. It is defined at least on one fact table. In most cases used for exposing transactional
data by joining the fact table with Attribute Views.
• Calculation View: Performs Engines cooperate with each
complex calculations not other. The SQL Optimizer
possible with other views and decides the best way to call
uses SQLScript. It can be each engine depending on the
defined as graphical view models
or scripted view.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 43


Attributes, Views, Facts, Cubes and Dimensions

• Attributes are the data • Fact Tables are measurements,


fields of one table row, e.g. metrics or facts of a business
the “Company Name”. process and are often located at the
Calculated Attributes center of a Star Schema (data
return simple calculations, cube) surrounded by its linked
Dimension Tables, typically master
e.g. table field text
data.
manipulations or measure Example: fact table can be the Sales
related operations. Order header table (you can also
use the sales order item table in the
• Views are combinations fact table if necessary).
and selections of data from
tables modeled to serve a
particular purpose.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 44


Exercise: SAP HANA Engines

There are no exercises for this Lesson.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 45


SAP HANA Modeling:
Working with Tables
Pros/Cons of Column store vs. Row store

When to use Row-based or Column-based Tables with SAP HANA?


• Column-based tables have advantages in the following cases:
• Calculations are performed only on few columns
• Table is searched based on values on few columns
• Table has large number of columns
• Table has large number of rows and columnar operations are required (aggregate, scan)
• High compression rates can be achieved because majority of columns contain only few distinct values
compared to number of rows
• Row-based tables have advantages in the following cases:
• The application needs to only process a single record at a time (many selects / updates of single records)
• The application typically needs to access a complete record or row
• Columns contain many distinct values so that the compression rate would be low
• Neither aggregation nor fast searching are required
• Table has a small number of rows

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 47


Altering Tables from/to Column store

Some Tips and Tricks regarding Row-based and Column-based Tables


• You can alter an existing table from columnar to row-based and vice versa
• SLT replicated tables are created as Column-based tables by default
• You can either alter the type of table manually for each table or write an SQL script to perform this
operation for a set of tables

In case you are wondering….


• In most cases, having the table as column table is the way to go. In many cases, the engines of
HANA can work more effectively with such tables.
• However there are certain use cases and valid scenarios for row tables:
• SAP BW on HANA uses row based tables for the so called Write Optimized DSOs, where the main
requirement is to have the best performance for uploading lot’s of records  So this row table (DSO) is an
interim staging area for data to be further processed (and transferred to column based tables)
• Generally, row based tables could be considered for storing configuration (which don’t appear in joins
with column tables) or staging tables for optimizing upload performance
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 48
Creating Tables Using SAP HANA Development

You can create Tables as design-time objects (.hdbtable):

The screen below shows you an example of the syntax used to create a table in a particular schema
using the SAP HANA Development perspective

Deprecated

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 49


Update

• CDS Artifacts are the recommended way of defining tables, views, entity
types, associations, as well as annotating data.
• It is the new and recommended way to define database artifacts.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 50


Core Data Services (CDS)

• CDS (Code Data Services) is a data definition


language (DDL) artifact which provides the
design time definition of the runtime database
objects. It’s also a Query and Expression
Language.
With this artifact it is possible to define:
• Entities
• Views
• Associations
• Annotations
• Etc…
• HANA CDS vs ABAP CDS:
• Two implementations based on the same specification. ABAP CDS is open, while HANA CDS is HANA
specific. ABAP CDS is stored in the ABAP Data Dictionary and HANA CDS is stored in the HANA Repository
with the extension ‘.hdbdd’ or on newer systems with ‘.hdbcds’.
• More at: Education training HA450, Reference Guide (PDF)

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 51


CDS vs SQL

• CDS simplifies the creation and association of


Tables and Views.

• Upon activation, columns are created or updated.

• Simplifies the transport: just one activation instead of


a series of SQL Statements.

• No need to specify the join on querying associations


on views:

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 52


CDS – Reusable Types

• Create Reusable Types for common table structures.

• Example: easily add record tracking of user and timestamp in


a standardized way.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 53


Creating Tables

• Standard SQL • SAP HANA • CDS: DDL File


Modeler Tools

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 54


Data Preview

• Easy way to Display Table/View Data.

• Select the table on the Catalog and right-click on it.

• Choose Open Data Preview

• You can see the Raw Data or perform some quick Analysis

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 55


Inserting Data

• Insert data to your table using standard SQL • Use the Import / Export tools in the SAP HANA
statements on a SQL Console Studio to import DDL and data from/to the SAP
HANA server or from/to your local client

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 56


Exercise: Creating tables

The exercises for this Lesson is Exercise 2-1 and 2-2 in the “Student
Exercise Manual”.

You have 10 minutes for this Exercise

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 57


SAP HANA Modeling:
Calculation Views
Calculation View: Concept

• A Calculation View is a column view of type calculation

• Calculation Views are used to address complex business scenarios. They are created using tables,
other calculation views or the former attribute and analytic views.

• Calculation Views can be created using a Graphical editor or an SQLScript editor.

Deprecated

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 59


Query on Calculation View

• It is a SQL View
• A Calculation View can be queried with a SQL statement just as a standard View
• The Calculation View is a Column View stored under the schema _SYS_BIC, as for Attribute Views,
Analytic Views and Procedures created using the Modeler Content tools in the SAP HANA Studio.
• The naming pattern is the following:

Syntax to select from Calculation View:


SELECT * FROM "_SYS_BIC".”<package name>/<calculation view name>”

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 61


Calculation over Attribute and Analytical Views

• Attribute and Analytical Views are deprecated. Currently you can create
a Calculation View and later on specify which type of Information View it
will be.
• Scripted Views are also deprecated. This feature has been replaced by
Table Functions.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 62


Unsupported Features

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 63


Defining Dimension Calculation Views

• Dimension Views give context to Master Data tables.


• Example: A table with Product names and numeric Supplier IDs but
no Company Names for these Suppliers can be linked to another
table with more information about the Suppliers, including Company
Name. Company Names have given context to the first table in this
case.
• It is a select of a subset of columns and rows from a data table
• They define attributes, which are usually not measurable (hence
the former Attribute Views)
• Dimensions typically join master data tables to each other, e.g.
“Plant” to “Material” or “Business Partner” to “Product”
• They can also be used to join the text tables with the master data
tables

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 64


Creating Dimension Calculation Views: Choosing Name & Type

We aim to create a summary view of the Business


Partner data for our company ITelO, compared to the full
replicated EPM table SNWD_BPA. Right-click on
Calculation Views under your Content-Package and
click on New

Enter Name, select DIMENSION as Data Category and


click on Finish

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 65


Creating Dimension Calculation Views: Selecting Tables

Add tables to Data Foundation – via drag & drop from the Catalog, or press the Add Objects button
(with the “+” sign)

Enter the table name (beginning)


in the popup, select the right
tables and press OK. For our
example we need the EPM Business
Partner table SNWD_BPA.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 66


Creating Dimension Calculation Views: Joining Tables

We create a Dimension Calculation View based on several joined tables, for example, to display more
contact details for our Business Partners:

• We join the SNWD_BPA and SNWD_BPA_CONTACT tables

• We may select the following attributes:


CLIENT,
NODE_KEY (Key Attribute),
EMAIL_ADDRESS,
COMPANY_NAME,
FIRST_NAME,
LAST_NAME

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 67


Business Partner contact details: The Joins

To join attributes, you may either right-click on the table and then click on Create Join or drag the join
arrow from one attribute on the first table to the attribute on the second table

Select the join type and cardinality

For our business scenario we will join the NODE_KEY on the left table with the PARENT_KEY on the
right table

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 68


Table Join Types and Unions
Returns rows when there is at least one match in both tables. Combines records
from the left and right table exactly when the specified criteria are met.
Inner Join If the criteria are not met, no record is created in the result set. Inner Join is used
even if not added (if there’s an implicit join defined using a SELECT from 2 tables).
Returns all rows from the left (right) table, even if there are no matches in the right
Left (Right) (left) table. If records match, they are combined, otherwise the columns are empty.
Outer Join It is the only “correct” type of join for Cube Calculation Views.

Returns all the rows from the left table, and all the rows from the right table.
If records fulfill the criteria, they are combined, otherwise columns will be empty.
Full Outer Join

Semantically an inner join that assumes that referential integrity is given, that is, the left table always
have an corresponding entry on the right table. Optimized or faster inner join where the right table is
Referential Join
not checked if no field from the right table is requested. Cannot be used if a filter is set on a field in
the right table.
Used to join a text table to a master data table (e.g. Material_ID  Description) as requirement for
description mapping. The text join always filters on one language, and thus one needs to specify a
Text Join language column in the text table. The language is filtered based on the view settings (per default
taken from the user profile)
Used to combine the result-set of two or more SELECT. The Union operation is popular for combining
plan and actual values like CO-PA. It is not supported in the former Attribute Views, Analytical Views.
Union

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 69


Table Join Types: Text Joins

• Text Join are used to join a text table to


a master data table.

• Text Joins acts as a Left Outer join and


can be used with SAP tables where the
language column (SPRAS) is present.

• For each attribute it is possible to define


a description mapping that will be
specific to the end users language.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 70


Creating Dimension Calculation Views: Choosing Attributes

Choose the attributes for the Dimension Calculation View.


Click on the circle or use context menu of the corresponding attribute to Add To Output as Attribute.
You can also use Apply Filter.

Use Column Properties to mark Key Attributes

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 71


Creating Dimension Calculation Views: Activating the View

Click on Save, to save the model in the repository

Right click on the Dimension Calculation View and click on Validate, to verify the syntax

Right click on the Dimension Calculation View and click on Activate or Redeploy. A runtime object
will be created in the Catalog Schema _SYS_BIC.

Save and Validate Save and Activate

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 72


Creating Dimension Calculation Views: Calculated Columns

Using a Calculated Column, we can clearly show


which Business Partners are Customers or Suppliers.
Right-click on Calculated Columns and click on New.

Enter Name and Expression as shown on the right


screen. Click on Validate.

Click on Add

Beware of the syntax, e.g. type of quotation marks for


”table_columns” vs. ‘values’. Functions differ from SQL!

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 73


Previewing Data from Dimension Calculation Views

Save, Validate and Activate as shown before

Right-click on your Attribute View and click on Data


Preview, or press the Data Preview button on the
Attribute View window

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 74


Displaying Charts for Dimension Calculation Views (1)

Switch from the Data Preview (Raw Data) View to Distinct Values and click on an Attribute to display
your first analytic graphs

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 75


Displaying Charts for Dimension Calculation Views (2)

Switch to the Analysis Tab to display more complex charts

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 76


Creating Dimension Calculation Views: Re-Opening the View

In your Content Package, open the Dimension Calculation View by double clicking on it.
Alternatively you can right-click on the Dimension Calculation View and click on Open.
Validate, Activate, Data Preview, etc.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 77


Copying Dimension Calculation Views

To copy an Dimension Calculation View:


Right click on the Calculation View node and click New
Check the button Copy from
Browse in the Content Package repository, and select the
Attribute View you want to copy or derive from
Click on Finish

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 78


Exercise: Creating Dimension Calculation Views

The exercises for this Lesson are Exercises 2-3 and 2-4 in the
“Student Exercise Manual”.

You have 20 minutes for the Exercises

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 79


Defining Cube Calculation Views

• Cube Calculation Views are multidimensional reporting models (“cubes”) where


Fact Tables (Star Join) are joined against modeled dimensions
(Dimension Calculation Views)
• Cube Calculation Views do not store data: data is read from joined tables and Joins and calculated
measures are evaluated at run time
• Can be used for example to model transactional data (sales order header joined with material
master)
• A selection of Measures (Key Figures) is taken to build the Star Join based on transactional data
• Similar idea as the classic “star schema”

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 80


What is a Star Schema?

• Data Warehousing data model concept, similar to SAP BW Product Time


Infocube dimension dimension
• A single object (Fact Table with measures and “facts” which
change dynamically with time) sits in the middle and is Fact
radially connected to dimension lookup tables (relatively Table
static) like a star
• Primary keys in each dimension are related to foreign keys Partner Country
in fact table dimension dimension

• Cons: Fact tables are normalized (no redundancies) but dimension tables are de-normalized
(contain redundancies). No easy aggregate building. Performance issues with big dimension tables.
Changes in semantic data model mean complex table reorgs.
• Pros: Intuitive data model. Relatively few joins and tables. Easy to maintain.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 82


Creating Cube Calculation Views: An EPM example

We create an Analytic View based on the EPM data model.


Our goal is to display aggregated Purchase Order amounts
classified by Business Partners and Products:

• We join the SNWD_PO (PO header) and SNWD_PO_I


(PO items) tables to build our Fact Table

• We use the following Dimension Calculation Views as


master data dimensions:
• Dimension Calculation View for Business Partners (based on
the joined tables SWND_BPA and SWND_BPA_CONTACT as
outlined on the last chapter)
• Dimension Calculation View for Products based on single
table SWND_PD

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 83


Creating Cube Calculation Views: Building Blocks

• Create a Cube Calculation View similarly as for Dimension


Calculation Views: Right-click on the Calculation Views node 
Click on New  fill the required fields (Name, Data Category:
CUBE, with Star Join)
• Add the required Dimension Calculation Views based on the
Business Partner and Product tables to the Star Join (you need to
previously create these Dimension Calculation Views as explained
before)
• Add the Purchase Order Header table (SNWD_PO) and Purchase
Order Items table (SNWD_PO_I) tables to the Join node.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 84


Creating Cube Calculation Views: Attributes and Measures

• Click on Semantics and mark the desired columns as Attributes or Measures


• You can also hide some columns to hide them from the result view

Attribute

Measure

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 85


Creating Cube Calculation Views: Join data and Activate

• On the Star Join level, join the Dimension Calculation View with the Fact Table defined above
• Click on Validate and then on Activate

Best Practice: Use Left Outer Join, rather than


Inner Join, to join the Fact Table to the master
data dimensions (Dimension Calculation Views)

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 86


Creating Cube Calculation Views: Data Preview

• Check the Cube Calculation View data using Data Preview:

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 87


Check aggregates using the SQL Editor

• You can use the SQL Editor to check aggregates for the tables:
SELECT partner_guid, SUM(gross_amount)
FROM "<epm_schema>".snwd_po
GROUP by partner_guid
ORDER BY 2 DESC;
SELECT supplier_guid, SUM(gross_amount)
FROM "_SYS_BIC"."<package_name>/CV_PO"
GROUP BY supplier_guid
ORDER BY 2 DESC;

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 88


Exercise: Create Cube Calculation Views

The exercises for this Lesson are Exercises 2-5, 2-6 and 2-7 in the
“Student Exercise Manual”.

You have 30 minutes for the Exercises

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 90


Variables and Input Parameters
Concepts

In Analytic and Calculation views you can create two


types of objects to parameterize the result returned by the
view:
• Variables
These are bound to attributes and are used for filtering.
They can only contain the values available in the Attribute
they relate to.
• Input Parameters
Can contain any value the reporting user has to enter to
parameterize the result. Therefore, a data type must be
specified for each Input Parameter.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 92 Confidential 92


Variable types

The following types of Variables are supported:


Type Description
Single Value Use this to apply a filter to a Single Value

Interval Use this where you want the user to specify a set start and end to
a selected Interval.
Range Use this when you want the end user to be able to use operators
such as “Greater Than” or “Less Than”.

Range Variable Example:

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 93 Confidential 93


Creating Variables

A variable restricts the results in the view for the


selected Attribute.
You select the Attribute in the view that you
want to filter on, and you also define the:
Selection Type: Whether selections should be
based on intervals, ranges or single values.
Multiple Entries: Whether multiple values of
the selection types should be allowed.
You can also define whether the Variable is
Mandatory or if it should have a Default Value.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 94 Confidential 94


Input parameter types

The following types of input parameters are supported:

Type Description
Currency Use this during currency conversion where the end user should
specify a source or target currency.
Date Use this to retrieve a date from the end user using a calendar
type input box.
Static List Use this when the end user should have a set list of values to
choose from.
Attribute Value When an Input Variable has this type, it serves the same
purpose as a normal Variable.
(none) If none of the above applies you do not have to specify an Input
Variable type. The Type can be left blank

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 95 Confidential 95


Creating input parameters

If we want the end user to decide whether Gross or


Net amount should be shown in a View, what we
first need to do is to create an Input Parameter to
be used in a calculation.
The Input Parameter can be of any suitable type,
for example a StaticList type.
In this example to the left the user can choose
either ”Gross” or ”Net” as the selection.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 96 Confidential 96


Calling Input Parameters

We also need somewhere to call the Input


Parameter from.
In for example a Calculated Measure, we can
reference the result of the user selected Input
Parameter.
This is done by calling it within double dollar signs,
see example:
if('$$INP_GROSS_OR_NET$$'=
'Gross',"GROSS_AMOUNT","NET_AMOUNT")

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 97 Confidential 97


Exercises: Variables and input parameters

There are no exercises for this Lesson

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 98


Using SQLScript and
Procedures
Concept

• SQLScript is a collection of extensions to Structured Query Language (SQL).

Data Type Extension Allows the definition of table types without corresponding tables
(CREATE TYPE)
Procedures To push data intensive logic into the database. Supported are
(CREATE PROCEDURE) declarative (side-effect free) and imperative procedures to
encapsulate complex queries and data flows
User Defined Functions Creates side-effect free Scalar or Table functions
(CREATE FUNCTION)

• SQLScript encourages to implement algorithms using a set-oriented paradigm instead of a


one tuple at a time paradigm.
• SQLScript allows using of imperative as well as declarative statements.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 100 Confidential 100
Data Type Extensions

Scalar Data Type :

The SQLScript type system is based on the SQL-92 type system and supports the following
primitive data types:

TINYINT, SMALLINT, INTEGER, BIGINT

DECIMAL(p, s), REAL, FLOAT, DOUBLE

VARCHAR, NVARCHAR, CLOB, NCLOB

VARBINARY, BLOB

DATE, TIME, TIMESTAMP

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 101 Confidential 101
Data Type Extensions

• Table Type: SQLScript also allows the definition of table types.


• Table types are used to define parameters for a procedure that represents tabular results, for
example an output table displaying the results of a procedure used to encapsulate complex queries.
• A table type is created using statement CREATE TYPE and can be deleted using statement DROP
TYPE.
• Syntax:

• CREATE TYPE [schema.]name AS TABLE


(name1 type1 [, name2 type2,...])
• DROP TYPE [schema.]name [CASCADE]

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 102 Confidential 102
SQLScript and Procedures

• Procedures are reusable processing blocks, and describe a sequence of data transformations.
• Procedures can have multiple input and output parameters (scalar or table types).
• DROP and CREATE statements are used to modify the definition of a procedure.

• A procedure can be created as read only (without side-effects) or read-write (with side-effects).
• Read-only procedures can only call other read-only procedures.
• Procedures can be created with different languages, but SAP HANA Studio supports only SQLScript.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 103 Confidential 103
Procedure

• The body of a procedure consists of a sequence of statements separated by semicolons.


• An intermediate variable, inside a procedure, is not required to be defined before it is bound by an
assignment.

• Cyclic dependencies that result from the intermediate result assignments or from calling other
functions are not allowed.
• A variable name is prefixed by “:” (colon) while used as input to another statement.
• A Procedure can be created using the SQL editor or using creation wizards available for the different
perspectives in the SAP HANA Studio (Modeler and Development perspectives).

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 104
Procedure creation using the SQL editor

• Syntax:
CREATE PROCEDURE {schema.}name
{({IN|OUT|INOUT} param_name data_type {,...})}
{LANGUAGE <LANG>} {SQL SECURITY <MODE>}
{READS SQL DATA {WITH RESULT VIEW <view_name>}} AS
BEGIN
...
END

▪ READS SQL DATA defines a procedure as read-only. Also optimizes Performance


▪ Implementation LANGUAGE can be specified . Default is SQLScript.

▪ WITH RESULT VIEW is used to create a column view for the output parameter of type table
▪ SQL SECURITY modes defines who can call the procedure:
- INVOKER: assigned privileges / - DEFINER: only the owner

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 105 Confidential 105
Calling a Procedure

• CALL - Procedure Called From Client


• A procedure (or table function) can be called by a client on the outer-most level, using any of the
supported client interfaces.

Syntax
CALL [schema.]name (param1 [, ...])

• For table output parameters it is possible to either pass a (temporary) table name or to pass one of
? or NULL.
The option NULL will display the output directly on the client output screen.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 106 Confidential 106
Calling a Procedure – WITH OVERVIEW

• CALL...WITH OVERVIEW From Client


• This CALL statement returns one result set that holds the information of which table contains the
result of a particular table’s output variable.
• This is used to populate an existing table by passing it as parameter.
• When passing ? (or NULL) to the output parameters, temporary tables holding the result sets will be
generated.
• Help Documentation

Syntax
CALL [schema.]name (param1 [, ...]) WITH OVERVIEW

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 107 Confidential 107
Calling a Procedure in Select Query

• When a procedure has been created with addition “WITH RESULT VIEW”, a column view is
generated. This column view can be used in an SQL SELECT statement.
• Column views also accept input parameters, which can be used in a query using the
‘PLACEHOLDER’ syntax as shown below.

Syntax

SELECT {[COL1, COL2,…] | * }


FROM <VIEW NAME>
WITH PARAMETERS (
‘PLACEHOLDER’ = (‘$$<attribute name>$$’,‘<value>’),
‘PLACEHOLDER’ = (‘$$<attribute name>$$’,‘<value>’),
…);

• Note: WITH RESULT VIEW is no longer supported on .hdbprocedure.


Use .hdbtablefunction if it is required.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 108
Syntax Tips

• Single quote ‘ ’ is used for values and double quote “ ” for identifiers

• Identifier and character value are case sensitive

• Identifier names without double quote are converted into upper case. Double
quotes can be used to prevent this conversion.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 109
Creation using the Modeler wizard

• Start Procedure creation wizard from context menu of package

Deprecated

• ! WITH RESULT VIEW not supported on .hdbprocedure. Use .hdbtablefunction instead.


© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 110
Create Stored Procedures on Repositories

• Press Ctrl+N and search for ‘procedure’

• Choose a folder, name it and your


schema

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 111
SQLScript: Calculation Engine Plan Operators

• Calculation engine plan operators (CE_* operators) encapsulate data-


transformation functionality

• It is an alternative to using SQL statements as their logic is directly implemented in


Deprecated
the calculation engine, i.e. the execution environment of SQLScript.

• Using Calculation Engine operators may lead to higher performance in some


cases, and can help structure the code in a simpler way

• Calculation Engine (CE) Functions - Rest in Peace


https://scn.sap.com/community/hana-in-memory/blog/2014/12/11/calculation-
engine-ce-functions--rest-in-peace

• They are still supported but not recommended

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 112
Functions

• Syntax:
CREATE [OR REPLACE] FUNCTION <function_name> (<parameter_clause>)
RETURNS <return_type>
[LANGUAGE <lang>] [SQL SECURITY <mode>]
[DEFAULT SCHEMA <default_schema_name>] [DETERMINISTIC] [WITH ENCRYPTION]
AS {
BEGIN
<function_body>
END | HEADER ONLY
}
• DETERMINISTIC is used for scalar functions to cache results
• WITH ENCRYPTION encrypts the function definition permanently
• HEADER ONLY is used to declare the function signature without specifying the body
• Help documentation

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 113
Using a Function

• A function used inside a select statement to modify the result of a selected column.

Syntax
SELECT [schema.]function (param1 [, ...]) FROM …

Example
SELECT body_mass_index (height, weight) FROM People;
Result:
BODY_MASS_INDEX(1.70, 70)
1 24,22

• If the function returns a table type you can perform a select on the function.

Syntax
SELECT * FROM [schema.]function (param1 [, ...])

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 114 Confidential 114
SQLScript: Control Statement CONDITIONAL

IF <bool-expr1>
Example:
THEN
SELECT count(*) INTO found
{then-stmts1} FROM books WHERE isbn = :v_isbn;

IF :found IS NULL THEN


{ELSEIF <bool-expr2>
CALL ins_msg_proc
THEN ('result of count(*) cannot be NULL');
{then-stmts2}} ELSE

{ELSE CALL ins_msg_proc


('result of count(*) not NULL - as expected');
{else-stmts3}}
END IF;
END IF

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 115 Confidential 115
SQLScript: Control Statement LOOP

WHILE <bool-stmt> DO FOR <loop-var> IN {REVERSE} <start> .. <end>


DO
{stmts}
{stmts}
END WHILE
END FOR

Warning:
Control Statements negatively impact the planner parallelization.
Avoid them if possible. If not, push them to the end of the queries and views so that the planner can
execute as many as parallel tasks before waiting for conditions to be met.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 116
SQLScript: Dynamic SQL

EXEC '<sql-statement>'

• Dynamic SQL statement is used to construct SQL statements at runtime in a procedure


• Dynamic SQL allows to use variables where they might not be supported in SQLScript. It
provides more flexibility in creating SQL statements.
• Optimization of dynamic SQL statement is limited
• It is not possible to bind result of a dynamic SQL statement to a SQLScript variable
• Dynamic SQL is prone to SQL injection
• EXEC '<sql-statement>‘ is used to construct dynamic SQL
• We recommend that you avoid dynamic SQL because it might have a negative impact
on security or performance

© 2017 SAP SE or an SAP affiliate company. All rights reserved. 117 Confidential 117
Exercise: Creating Procedures

The exercises for this Lesson are Exercises 3-1, 3-2 and 3-3 in the
“Student Exercise Manual”.

You have 30 minutes for the Exercises

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 118
Export and Import
Exporting and importing with SAP HANA

HANA supports export and import of Information Models, tables and more
Export and Import is handled via SAP HANA Studio
 Client-side export/import: to/from client PC running SAP HANA Studio
 Server-side export/import: to file system of SAP HANA database server

Information Models

DB Server

Tables
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 120
Client-Side Export/Import of Information Models

• Client side export allows to export models and tables (table import to and from client supported from
SP4) to client file system.

• It does not require access to file system of HANA server

• Exported objects (xml files) can be changed

• See Import / Export tools on the Quick Launch or clicking on the File Menu

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 121
Server side export and Import

• Server side export allows you to export information


models to the file system where the SAP HANA
server is installed

• Packages must be assigned to a Delivery Unit for


server side export

• You can also export Delivery units to your client, for


example for test transports of development content
between systems

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 122
Import with CDS

• CDS can also be used to import data from CSV files.

• Table Import configuration file:


import = [ {
table = "mycompany.tests.TiTest::inhabitants";
schema = "AMT";
file = "mycompany.tests.TiTest:inhabitants.csv";
header = false;
} ];

• Triggered upon file activation!

• More at: Import Data with CDS Table-Import

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 123
Exercise: Export and Import

The exercises for this Lesson are Exercises 4-1 and 4-2 in the
“Student Exercise Manual”. Exercises 4-3 and 4-4 are optional.

You have 10 minutes for the Exercises

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 124
SAP HANA Performance
Modeling

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 126
General Principles

▪Minimize the join operations ▪ Minimize data transfer between the


▪ Avoid long join chains engines
▪ Avoid joins between big tables ▪ Prefer execution of calculation in lower layers,
▪ Avoid joining tables with n:m cardinality instead of pushing data up and calculate there

▪Reduce data amount as early as possible


▪ Use data aggregation ▪ Avoid expensive calculation or data
▪ Use data filters where possible manipulation
▪ Row based data base expressions are expensive
▪Avoid huge query result sets ▪ Intermediate results needs to be written into
▪ Data transfer to the UI clients also requires time buffer and takes additional time
▪ Too many data can be anyway no analyzed properly ▪ Complex expressions, e.g. IF, CASE statements

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 127
Join operations

• Joins are well optimized in the join engine.


• Cascaded Joins are very expensive and not always lead to right results. Cascade carefully.
• Left outer join is normally faster than inner join. Left Join are almost equally fast as Referential
Join.
• Currently, one single join operation is executed by 1 core at maximum (Multiple Join are
parallelized across multiple cores).
• Avoid joins on calculated fields, e.g. concatenating two fields into one and execute a join on it.
Materialize the concatenated field (if not done by the engine).
• Avoid non-equijoin predicates on column table as column engine does not natively support join
predicates other than equality condition.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 128
Filter Operations

CONSTRAINT
▪ applies on a table of a cube calculation view
▪ is forced with inner join, and optional with left / referential join
▪ is executed before join and aggregation
▪ reduces data amount very early and for that it is very fast (especially when constraint is applied on a dimension
table)

WHERE
▪ applies on a tuple and has different semantic than constraint
▪ is very fast on column tables

HAVING
▪ is used to reduce the final result set after aggregation. However it has no performance gain
e.g. HAVING salesAmount > 10000

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 129
Database Expressions

▪ Avoid database expressions which need to be executed before aggregation


▪ Performance is critical as calculation happens on every single record and needs to be written into
an intermediate runtime buffer, too
▪ In a Calculation View you can push the expressions to the top while doing the aggregations at the
bottom. Aggregate before and do database expressions later
▪ If not avoidable, check if persisting the calculated field in the table could be a valid option (see SQL
lesson)

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 130
SQLScript

• Query optimizer creates an execution plan that involves both storage engines even if the data reside
completely in the column store if feature used in query is not supported by column engine.
• Query should be formulated in such a way that minimizes data transfer between different engines.
• Avoid implicit type casting.
• Reduce complexity of SQL Statements. It helps in identifying common sub-expression.
• Reduce dependencies between different SQL statement and use declarative constructs to enable parallel
execution of SQL statements.
• Executing dynamic SQL is slow because compile time checks and query optimization must be done for
every invocation of the procedure.
• Avoid CURSOR (and other imperative constructs) as parallelization can’t be done.
• Consider the impact of expensive calculations (like unit and currency conversion).

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 131
SQLScript

The column engine can natively execute queries that are


logically equivalent to queries that can be expressed in
the following format.

SELECT <column engine expressions separated by comma>


FROM <column engine FROM specifications separated by comma>
[ WHERE <column engine filter condition> ]
[ GROUP BY <column engine expressions separated by comma> ]
[ HAVING <column engine filter condition> ]
[ ORDER BY <column engine expressions with optional
ASC | DESC separated by comma> ]
[ LIMIT <any expression> [OFFSET <any expression> ] ]

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 132
Partitioning

Typical use cases for partitioning

• Column table limitation of storing max. 2 billion records without partitioning

• Load balancing: individual partitions may be distributed over the landscape. Queries could be
processed on multiple servers.

• Parallelization: operations are parallelized by using several threads per table

• Partition Pruning: scans on relevant partitions only and reduces load. Precondition is, that the query
must match the given partition specification

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 133
Performance Analysis

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 134
Execution Time measurement

Query execution time can be measured directly by executing the


query in the SAP HANA Studio.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 135
Measure Expensive SQL Statement

Configure the measurement of


expensive statements
 System context menu in the
Navigator  Administration
 Select Trace Configuration tab. Edit
config for the Expensive
Statements Trace.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 136
Measure Expensive SQL Statements
Check the traced SQL statements:
Administrator view  Performance Tab  Expensive Statements Trace

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 137
Explain Plan

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 138
Explain Plan

Column name Description


OPERATOR_NAME Name of an operator.
OPERATOR_DETAILS Details of an operator. Predicates and expressions used by the operator are
shown here.
OBJECT_NAME Name of database tables and views accessed by an operator .
SUBTREE_COST Estimated cost of executing the subtree starting from an operator. The unit of
this value is time in seconds, but the absolute value would not match the actual
execution time. This value is only for relative comparison between different
subtrees.
INPUT_CARDINALITY Estimated input row count of an operator. This is available only for operators
accessing tables and views directly. For column store, estimation is done in row
granularity, but for row store, estimation is done in page granularity and there
can be large error for small tables.
OUTPUT_CARDINALITY Estimated output row count of an operator.
OPERATOR_ID Unique ID of an operator. IDs are integers starting from 1.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 139
Visualize Plan

Right click on the SQL statement, and select Visualize Plan (from SP4), then
• Right click on the yellow box and select Execute
• Open the yellow box using the triangle to see the Column Plan

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 140
Configure Performance Trace

To trace all SQL statements, you can configure it. It can be restricted by user.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 141
Execute Performance Trace

After Starting the trace, execute query. Stop tracing once execution is over.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 142
Analyze Performance Trace

• Traced file is available under “Diagnosis Files”.


• In order to analyze trace file, access to the analyzer tool in HANA server is required.
• It is also helpful to download the traced file and attach it while contacting HANA team for
performance issue.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 143
Analyze Performance Trace

To analyze trace file, application HDBAdmin.sh is used. It’s required to have HDB
administrator authorization to use it.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 144
Debugging Tools

• It is also possible to debug your SQLScript code


• The Development Perspective in the SAP HANA Studio offers various tools to
debug your applications

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 145
Exercises: HANA Performance

There are no exercises for this Lesson

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 146
User Management & Security
User Management and Security in SAP HANA

Create Users
 Assign Initial
Passwords
 Important User
Parameters

Manage Users
Assign Security  Lock Users
 Control Access to  Reset Passwords
Objects
 Check User
 Row-Level Security Privileges
 Restrict allowed actions  Integration with BI

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 148
Types of Privileges

When accessing the SAP HANA database using a client interface (such as ODBC, JDBC, MDX), any
access to data must be backed by corresponding privileges. Different schemes are implemented

Object Privilege System Privilege


Object SYSTEM
 Privilege SQL statement type  Used for administrative tasks.
(for example, SELECT, Privilege Privilege
 System Privileges are
UPDATE, and CALL…) assigned to users and roles.
Authorization
Concept

Package Privilege Analytic Privilege


Package Analytic
 Restrict the access to and  Analytic Privileges are used
Privilege Privilege
the use of packages in the to provide row-level
repository authorization Views.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 149
Object Privilege

In the SAP HANA database, a number of privileges are available to control the authorization of
SQL commands. Following the principle of least privilege, users should only be given the
smallest set of privileges required for their role.
Two groups of SQL Privileges are available:

System Privileges
These are system-wide privileges that control some general system
activities mainly for administrative purposes, such as creating
schema, creating and changing users and roles.

Object Privileges
These privileges are bound to an object, for example, to a database
table, and enable object-specific control activities, such as SELECT,
UPDATE, or DELETE to be performed.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 150
Analytic Privilege - The Concept

Analytic Privileges are used to control access Implement row-level security with Analytic
to SAP HANA data models Privileges
• Without Analytic Privilege, no data can be • Restrict access to a given data container to
retrieved from selected Attribute Values
▪ Attribute Views ▪ Field from Attribute View
▪ Analytic Views ▪ Field from Attribute View used in Analytic View
▪ Calculation Views ▪ Private Dimension of Analytic View
▪ Attribute field in Calculation View
▪ Combinations of the above
▪ Single value, range, IN-list

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 151
User Provisioning - User and Role Concept

You can use the Security to manage users, roles and assign privileges

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 152
Pre-delivered Roles

SAP HANA comes with several pre-defined / standard roles:


Roles that should (must) be used unchanged
 PUBLIC – minimal privileges for a user to work with the database at all
 Is implicitly granted whenever a user is created

Role Templates
 CONTENT_ADMIN – the only role in the system with vital privileges, e.g.:
▪ SQL Privileges on Schema _SYS_BIC – with GRANT OPTION
▪ SQL Privileges on Schema _SYS_BI – with GRANT OPTION
 MODELING – a very richly privileged role that enables
▪ Creation and activation of Information Models
▪ Creation and activation of Analytic Privileges
 MONITORING – role with full read-only access to all meta data, monitoring and statistics

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 153
Web-based Workbench Roles

• SAP HANA Web-based Development Workbench provides an easy access to HANA features.
• It has basically the same features as the SAP HANA Studio on Eclipse.

• To use them, you will need the role:


• sap.hana.xs.ide.roles::Developer

• And also one role for each feature:


• sap.hana.xs.ide.roles::CatalogDeveloper

• sap.hana.xs.ide.roles::EditorDeveloper

• sap.hana.xs.ide.roles::SecurityAdmin

• sap.hana.xs.ide.roles::TraceViewer

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 154
Exercise: User Management and Security

There are no exercises for this Lesson

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 155
A Data Consumption example
using Microsoft Excel
Business Example

Microsoft Excel is still the primary tool of choice for


business users to analyze data

Using the PivotTable and PivotChart features,


multidimensional reporting can provide valuable insight

Using SAP HANA, business users can create reports in


MS Excel that give an overview on operational level
(OLTP) data in an aggregated (OLAP) way, thus providing
real-time insight into business processes

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 157
Microsoft Excel

Multidimensional reporting is
available via Excel Pivot Tables
“Quick and dirty” cross-tab style
reporting via Excel.
There are disadvantages as well:
 The report definition is only available locally
(workarounds exist)
 Subject to performance limitations of the
desktop machine where Excel runs

BusinessObjects Analysis, Edition for


Microsoft Office is also worth looking
into!
It’s the successor of BEx Analyzer for
Excel and offers rich functionality.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 158
Procedure: Access HANA models from Excel I

1. From the Data tab on the Excel tabstrip, select


the “From Other Sources” button, and select the
“From Data Connection Wizard” option

2. Select the “Other/Advanced item” from the list


and click Next

3. Select the “SAP HANA MDX Provider” from the


list and click OK

4. Provide the login credentials to the SAP HANA


system

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 159
Procedure: Access HANA models from Excel II

5. Select one of the Views you have created earlier then


click Next

6. On the next window, click the Finish button

7. Select PivotChart and PivotTable report and click OK

8. You might need to provide your password to SAP HANA


again

9. Play around by selecting fields from the right hand side


list and create different charts

10. Think about possible business questions and answers


© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 160
Demonstration: Access HANA models from Excel

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 161
Exercise: Access HANA models from Excel
(OPTIONAL)

The exercises for this Lesson are Exercises 5-1 and 5-2 in the
“Student Exercise Manual”.

You have 20 minutes for the Exercises

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 162
Obrigado! Inovação + Parceiros + SAP

Ivan Mirisola Lucas Rigo


Partner Integration Expert Partner Integration Expert
SAP Co-Innovation Lab Brasil SAP Co-Innovation Lab Brasil
ivan.mirisola@sap.com lucas.rigo@sap.com
Learn More

• OpenSAP Courses: • Help Documentation:


• https://open.sap.com/courses/hana6
• SAP HANA Platform Portal
• https://open.sap.com/courses/hana5
• https://open.sap.com/courses/hana4 • SAP HANA Master Guide
• https://open.sap.com/courses/hana3
• https://open.sap.com/courses/hana2 • SAP HANA Administration Guide
• https://open.sap.com/courses/hana1
• SAP HANA Modeling Guide

• SAP HANA Developer Guides:


• Quick Start
• For SAP HANA Studio
• For SAP HANA Web Workbench

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 164
© 2017 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 165

You might also like