SAP HANA
Lesson Name: Database Independent Code-to-Data.
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 2
Lesson Objectives
After completing this lesson, participants will be
able to –
Know about basics of OPEN SQL
Features of OPEN SQL
New syntaxes and statements of OPEN SQL in SAP ABAP
Performance rules and limitations of OPEN SQL
Basics of Core Data Services (CDS)
Demo on CDS
CDS view Definition Features
Copyright © Capgemini 2015. All Rights Reserved 3
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 4
Introduction to OPEN SQL
Open SQL in our ABAP application server is
the database abstraction layer calling an SQL
like syntax.
It is the database abstraction layer and actually
the only database abstraction layer that has a
common semantic for all of SAP supported
databases.
Copyright © Capgemini 2015. All Rights Reserved 5
Introduction to OPEN SQL
This is important, if we are talking about
migration to SAP HANA/Database migration in
general.
No problem in migrating Open SQL from one
database to another because it has the same
semantics on all databases & you can use it as
before.
Copyright © Capgemini 2015. All Rights Reserved 6
Introduction to OPEN SQL
Copyright © Capgemini 2015. All Rights Reserved 7
Introduction to OPEN SQL
Open SQL aspires to
Enable the application of the Code-to-Data
paradigm
Provide more standard SQL features
Enable the consumption of SAP HANA-specific
features
With ABAP 7.4 and above, what's important is that
Open SQL will really help you doing the code
pushdown with a very easy way.
Copyright © Capgemini 2015. All Rights Reserved 8
Introduction to OPEN SQL
Copyright © Capgemini 2015. All Rights Reserved 9
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 10
Features of Open SQL in ABAP 7.4 SP2 and
beyond.
Syntax enhancements:
Escaping of host variables
Comma-separated select list
SELECT list enhancements:
Aggregation functions
Literals
Arithmetical expressions
Copyright © Capgemini 2015. All Rights Reserved 11
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 12
New Open SQL Syntax
Comma separated element list
Escaping of host variables
Target type inference
Note:
Very important for you to know that you don't need to
change your whole report now to the new SQL
statement.
The old style will stay intact so you will still be able to use
it.
Copyright © Capgemini 2015. All Rights Reserved 13
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 14
New features of OPEN SQL:
New SELECT List Features
Aggregation functions
Literal values
Arithmetic expressions
Copyright © Capgemini 2015. All Rights Reserved 15
New features of OPEN SQL:
Literal Values
• Can now be used in the SELECT list
• Allow for a generic implementation of an
existence check
Copyright © Capgemini 2015. All Rights Reserved 16
New features of OPEN SQL:
Arithmetic Expressions
• +, -, *, DIV, MOD, ABS, FLOOR, CEIL
• Remember: Open SQL defines a semantic
for these expressions common to all
supported databases
• Refer to the ABAP documentation to see
which expression is valid for which types
Copyright © Capgemini 2015. All Rights Reserved 17
New features of OPEN SQL:
Open SQL enhancements
SELECT list enhancements:
Conditional expressions
Copyright © Capgemini 2015. All Rights Reserved 18
New features of OPEN SQL:
Open SQL enhancements
Expressions in
HAVING clause
JOIN statements
Client handling
Copyright © Capgemini 2015. All Rights Reserved 19
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 20
List Of Open SQL Statements in SAP ABAP
The open SQL statements are:
INSERT
Insert record from internal table
Syntax:
INSERT <DB TABLE> FROM TABLE <INTERNAL TABLE>.
Insert record from work area
Syntax: INSERT <DB TABLE> FROM <WA>.
Copyright © Capgemini 2015. All Rights Reserved 21
List Open SQL Statements in SAP ABAP
The open SQL statements are:
UPDATE
Update record from internal table
Syntax:
UPDATE <DB TABLE> FROM TABLE <INTERNAL TABLE>.
Update record from work area
Syntax: UPDATE <DB TABLE> FROM <WA>.
Copyright © Capgemini 2015. All Rights Reserved 22
List Open SQL Statements in SAP ABAP
The open SQL statements are:
MODIFY
Update record from internal table
Syntax:
MODIFY <DB TABLE> FROM TABLE <INTERNAL TABLE>.
Update record from work area
Syntax: MODIFY <DB TABLE> FROM <WA>.
Copyright © Capgemini 2015. All Rights Reserved 23
List Of Open SQL Statements in SAP ABAP
The open SQL statements are:
DELETE
Update record from internal table
Syntax:
DELETE <DB TABLE> FROM TABLE <INTERNAL TABLE>.
Update record from work area
Syntax: DELETE <DB TABLE> FROM <WA>.
Copyright © Capgemini 2015. All Rights Reserved 24
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 25
Open SQL - Performance Rules:
To improve the performance of the SQL and in turn
of the ABAP program, one should take care of the
following rules-
Keep the Result Set Small
Using the where clause
If only one record is required from the database, use SELECT
SINGLE whenever possible .
Copyright © Capgemini 2015. All Rights Reserved 26
Open SQL - Performance Rules:
Minimize the Amount of Data Transferred
Restrict the number of lines
If only certain fields are required from a table, use the
SELECT <field1> <field2> INTO ... statement
Restrict no of columns
Use aggregate functions
Using Internal Tables to Buffer Records
To avoid executing the same SELECT multiple times (and
therefore have duplicate selects), an internal table of type
HASHED can be used to improve performance.
Copyright © Capgemini 2015. All Rights Reserved 27
Open SQL - Performance Rules:
Minimize the Number of Data Transfers
Avoid nested select loops
An alternative option is to use the SELECT .. FOR ALL
ENTRIES statement. This statement can often be a lot more
efficient than performing a large number of SELECT or
SELECT SINGLE statements during a LOOP of an internal
table.
Use dictionary views
Use Joins in the FROM clause
Use subqueries in the where clause
Copyright © Capgemini 2015. All Rights Reserved 28
Open SQL - Performance Rules:
Minimize the Search Overhead
Use index fields in the where clause
When accessing databases, always ensure that the correct
index is being used .
Reduce the Database Load
Buffering
Logical databases
Avoid repeated database access
Copyright © Capgemini 2015. All Rights Reserved 29
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 30
Limitations of OPEN SQL:
In OPEN SQL we can only use reference tables that
are managed by/in the “ABAP dictionary”.
OPEN SQL does not support DML statements like
create table.
OPEN SQL does not support “advanced” SQL
statements like TRUNCATE, MERGE, ROLLUP.
In OPEN SQL you can’t use aggregate functions
like sum,avg.
Copyright © Capgemini 2015. All Rights Reserved 31
Limitations of OPEN SQL:
OPEN SQL does not support most column functions
like SUBSTR, CONCAT (||) and “case expression”
in both the select and where clauses.
OPEN SQL does not allow you to write predicates
( where conditions) between more than one colum
… so you can’t write the following condition:
where t1.col1 <> t1.col2
Copyright © Capgemini 2015. All Rights Reserved 32
Limitations of OPEN SQL:
OPEN SQL does not allow to write predicates
( where conditions) on columns of a table joined
with left (or right ) join. So we can’t write the
following SQL:
select … from t1 left join t2
where t2.col = ‘x’
Copyright © Capgemini 2015. All Rights Reserved 33
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 34
Introduction to Core Data Services (CDS)
With the availability of the SAP HANA platform
there has been a paradigm shift in the way
business applications are developed at SAP.
The rule-of-thumb is simple: Do as much as
you can in the database to get the best
performance.
CDS is a data modeling infrastructure for
defining and consuming semantic and reusable
data models on the database, rather than on
the ABAP server, regardless of the database
system used.
Copyright © Capgemini 2015. All Rights Reserved 35
Introduction to Core Data Services (CDS)
Technically, it is an enhancement of SQL which
provides you with a data definition language
(DDL) for defining semantically rich database
tables/views (CDS entities) and user-defined
types in the database.
CDS entities and their metadata are extensible
and optimally integrated into the ABAP Data
Dictionary and the ABAP language.
Copyright © Capgemini 2015. All Rights Reserved 36
Introduction to Core Data Services (CDS)
Copyright © Capgemini 2015. All Rights Reserved 37
Introduction to Core Data Services (CDS)
Copyright © Capgemini 2015. All Rights Reserved 38
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 39
CDS in ABAP
Advantages
Semantically rich data models, i.e. CDS builds on
the well-known entity relationship model and is
declarative in nature, very close to conceptual
thinking.
Compatibility across any database platform, i.e.
CDS is generated into managed Open SQL views
and is natively integrated into the SAP HANA layer.
Copyright © Capgemini 2015. All Rights Reserved 40
CDS in ABAP
Advantages
Efficiency, i.e. CDS offers a variety of highly efficient
built-in functions — such as SQL operators,
aggregations, and expressions — for creating
views.
Extensibility, i.e. Customers can extend SAP-
defined CDS views with fields that can be
automatically added to the CDS view.
Copyright © Capgemini 2015. All Rights Reserved 41
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 42
Demo on CDS
ABAP CDS View Demo
Advanced View Definition in ABAP
Data Preview
Open SQL Consumption
Copyright © Capgemini 2015. All Rights Reserved 43
Demo on CDS
Advanced View Definition in ABAP
Copyright © Capgemini 2015. All Rights Reserved 44
Demo on CDS
Data Preview
Copyright © Capgemini 2015. All Rights Reserved 45
Demo on CDS
Consumption of CDS View
Copyright © Capgemini 2015. All Rights Reserved 46
Demo on CDS
Definition & Consumption of an ABAP CDS View
Definition in an ABAP DDL Source (R3TR DDLS)
Definition only possible with ABAP Development
Tools in Eclipse/HANA Studio (not via transaction
SE11)
Consumption via
Open SQL
Data Preview (context menu in ADT)
SAP List Viewer
SAP NetWeaver Gateway (OData Model)
Copyright © Capgemini 2015. All Rights Reserved 47
CONTENTS
Introduction To OPEN SQL
Features Of OPEN SQL
New OPEN SQL Syntax
New Features of OPEN SQL
List of OPEN SQL Statements in SAP ABAP
Performance Rules of OPEN SQL
Limitations of OPEN SQL
Introduction to CDS
CDS in ABAP
Demo on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 48
CDS View Definition Features
CDS View Definition Features
Projection List:
Client Dependency
Semantic Information (Key)
Aliases
Aggregation
Literals
Arithmetic Expressions
Conditional Expressions
View-on-View
CDS View Extensions
CDS View with Input Parameters
Copyright © Capgemini 2015. All Rights Reserved 49
CDS View Definition Features
ABAP CDS View: Projection List
Client-dependent view; no explicit client field
necessary
Semantic information (key field)
Aliases
Literal values:
C-sequence literals (Max length: 1333 )
Signed integer literals (4-Byte)
Aggregation functions:
MIN, MAX, COUNT, AVG, SUM
Alias required for function results
Copyright © Capgemini 2015. All Rights Reserved 50
CDS View Definition Features
View-on-View
View can have other views as data basis
No restriction on the number of layers
Copyright © Capgemini 2015. All Rights Reserved 51
CDS View Definition Features
CDS View Extensions
Extend base views with new fields
Copyright © Capgemini 2015. All Rights Reserved 52
CDS View Definition Features
CDS View with input
parameters
Comma-separated list of scalar
input parameters and
corresponding type
Supported parameter types:
•Predefined data type like
abap.char(char_len)
•Name of a data element
Copyright © Capgemini 2015. All Rights Reserved 53
CDS View Definition Features
• Consumption in a CDS View
Copyright © Capgemini 2015. All Rights Reserved 54
CDS View Definition Features
• Consumption via Open SQL
Check if the feature is supported
Provide (mandatory) input parameter(s)
Suppress syntax warning using the pragma
Provide a “fallback“ implementation / some error
handling
Copyright © Capgemini 2015. All Rights Reserved 55
CDS View Definition Features
Consumption via OpenSQL
Copyright © Capgemini 2015. All Rights Reserved 56
Summary
In this lesson, you have learnt:
Basic Concepts of OPEN SQL
Features of OPEN SQL
OPEN SQL Syntaxes and Statements
Performance Rules and Limitations of OPEN SQL
About Core Data Services
CDS in ABAP
Demos on CDS
CDS View Definition Features
Copyright © Capgemini 2015. All Rights Reserved 57
Review Questions
OPEN SQL Statements are those statements which
are used to -------- or --------- database table data.
For OPEN SQL statements insertion in database
table is possible in --------- way/ways.
Open SQL in ABAP application server is the -------
---------layer calling an SQL like syntax.
When using Open SQL statements in an ABAP/4
program, you must ensure the following.
a) The database system being addressed must be
supported by SAP.
b) The database tables being addressed must be defined
in the ABAP/4 dictionary.
c) Both a and b
d) None
Copyright © Capgemini 2015. All Rights Reserved 58
Review Questions
Which of the following statements are correct?
a) A database interface translates SAP’s Open SQL
statements into SQL commands specific to the
database in use. Native SQL statements access the
database directly.
b) When you use Native SQL, the addressed
database tables do not have to be known to the
ABAP/4 dictionary. In Open SQL, the addressed
database tables must be defined in the ABAP/4
dictionary.
c) There is automatic client handling in Native SQL
whereas clients must always be specified in Open
SQL.
Copyright © Capgemini 2015. All Rights Reserved 59
Thank you
Copyright © Capgemini 2015. All Rights Reserved 60