ABAP On HANA - OpenSQL - AMDP - CDS

You might also like

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

ABAP ON HANA

Anversha Shahulhameed
Lead Consultant

10-Jan-2018

© 2017 Wipro wipro.com confidential 1


Agenda

1 ABAP Shift to HANA Paradigm, Adv. OPEN


SQL and Basic Join operations.

2 ABAP CDS Views, advanced features etc.

AMDP methods, Consuming in ABAP and


3
usage of CE Functions.

4 HANA SQL Best Practices


OPEN SQL

Paradigm changes in developing applications

ABAP ABAP on HANA

Application

Mass Mass
data
Database data

 Push down data intense computations and calculations to the HANA DB layer .
 Avoid bringing all the data to the ABAP layer and the processing the data to do
computations.
 Code-to-Data paradigm in the context of developing ABAP applications optimized for
HANA.

© 2017 Wipro wipro.com confidential 3


OPEN SQL

Moving from ABAP to SAP ABAP on HANA


Shift in priorities of classic golden SQL rules for SAP HANA

Shift in priorities for SAP HANA

 Avoid selecting large numbers of not


required columns

 Prefer array operations for INSERT,


UPDATE und DELETE when changing
many records
 Avoid nested SELECT loops

 In most cases SAP HANA does not


require secondary indices

 Keep unnecessary load away from the


database
 Code pushdown for data-intensive
calculations to benefit from SAP HANA

© 2017 Wipro wipro.com confidential 4


OPEN SQL

Open SQL vs Native SQL.

 Open SQL allows you to access the database tables declared in the ABAP dictionary regardless of the database
platform that the R/3 system is using.
 Native SQL allows you to use database-specific SQL statements in an ABAP/4 program. This means that you can use
database tables that are not administered by ABAP dictionary, and therefore integrate data that is not part of the R/3
system.

© 2017 Wipro wipro.com confidential 5


OPEN SQL

Advantages of using Open SQL to do code push down


 Your ABAP code will remain database agnostic and will run on any ABAP server independent what
is the underlying database

 You implicitly take advantage of all transparent optimizations that have been achieved in the
Database Interface level

 All default performance optimizations like use of buffer and house keeping activities like client
handling etc are automatically taken care.

How do we use open SQL.

 Start using the new Open SQL syntax. Remember it is easy to convert your existing Open SQL
statements to new syntax without any side effects.

 Use aggregate functions where relevant instead of doing the aggregations in the ABAP layer.

 Use arithmetic and string expressions within Open SQL statements instead of looping over the data
fetched to do the arithmetic and string operations

 Use computed columns in order to push down computations that would otherwise be done in a
long loops

 Use CASE and/or IF..ELSE expressions within the Open SQL in order embed the logic of conditional
expression which in the past would have been done after fetching the results from the database.

© 2017 Wipro wipro.com confidential 6


OPEN SQL

Advanced Open SQL


Implemented by ABAP statements, this is a subset of the Structured Query Language (SQL) comprising the DML (Data
Manipulation Language) part. The statements of Open SQL use the Open SQL interface to access, independently of the
platform, the database tables of the database of an AS ABAP that are defined in the ABAP Dictionary.

Basic idea: support more standard SQL features(for SAP HANA as well as for
traditional database platforms)

Extended JOIN-support
 it is possible to nest JOIN-statements (i.e. to specify JOINson the ‘right hand-side’ of a
JOIN-condition)

Support for literals


 ABAP constants and ABAP variables can be used in the projection list

Expression support
 CASE-statements can be used in the projection list, nesting is possible
 Arithmetic expressions for integral, decimal and floating point calculations (e.g. +, -, *, DIV,
MOD)
 String expressions (concatenation of columns with &&)
 SQL functions (e.g. CAST)

© 2017 Wipro wipro.com confidential 7


OPEN SQL

Advanced Open SQL


Example

SELECT product_id && ',' && @space && category AS product, concatenation of columns
CASE tax_tarif_code
WHEN 1 THEN price * @lc_factor_1
WHEN 2 THEN price * @lc_factor_2 CASE-statement
WHEN 3 THEN price * @lc_factor_3
END AS price_vat, projection list separated by
currency_code AS currency commas
FROM snwd_pd
INTO CORRESPONDING FIELDS of @ls_result ABAP constants / variables
WHERE product_id IN @so_prod. escaped by @
WRITE: / ls_result-product,
ls_result-price_vat CURRENCY ls_result-currency,
ls_result-currency.
ENDSELECT.

© 2017 Wipro wipro.com confidential 8


OPEN SQL

OPEN SQL - Advances

 Maximum number of tables supported in Open SQL JOIN clauses has been increased to 50
 Maximum number of sub-queries supported in an Open SQL statement has been increased from
9 to 50

© 2017 Wipro wipro.com confidential 9


OPEN SQL

Select – INNER JOIN

Returns all rows when there is at


least one match in BOTH tables

SELECT column name(s)


FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

© 2017 Wipro wipro.com confidential 10


OPEN SQL

Select – LEFT OUTER JOIN

Returns all rows from


the left table (table1),
with the matching rows
in the right table
(table2).
The result is NULL in the
right side when there is
no match
SELECT column name(s)
FROM table1
Left Outer Join table2
ON table1.column_name=table2.column_name;

© 2017 Wipro wipro.com confidential 11


OPEN SQL

Select – RIGHT OUTER JOIN

Returns all rows from the


right table (table2), with
the matching rows in the
left table.
The result is NULL in the
left side when there is no
match

SELECT column name(s)


FROM table1
Right Outer Join table2
ON table1.column_name=table2.column_name;

© 2017 Wipro wipro.com confidential 12


OPEN SQL

Select – FULL OUTER JOIN

Returns all rows from the


left table (table1) and
from the right table
(table2).
The result is combination
of the result of both LEFT
and RIGHT joins
SELECT column name(s)
FROM table1
FULL Outer Join table2
ON table1.column_name =table2.column_name;

© 2017 Wipro wipro.com confidential 13


OPEN SQL

Select – UNION / UNION DISTINCT

Returns all rows from both the tables without duplicates


 Each SELECT
statement within the
UNION must have the
same number of
columns.

 The columns must


also have similar data
types, But can vary in
length

SELECT column name(s) FROM table1 WHERE


<CONDITION1>
UNION / UNION DISTINCT
SELECT column name(s) FROM table2 WHERE
<CONDITION2> ;

© 2017 Wipro wipro.com confidential 14


OPEN SQL

Select – UNION ALL / INTERSECT / EXCEPT

UNION INTERSECT EXCEPT


UNION
Return all rows from both the tables
with duplicates

INTERSECT
Returns the distinct rows from both SELECT column name(s) FROM table1
the tables
WHERE <CONDITION1>
UNION ALL / INTERSECT/EXCEPT
SELECT column name(s) FROM table2
EXCEPT WHERE <CONDITION2> ;
Returns distinct rows from left table
that aren’t in the right side table

© 2017 Wipro wipro.com confidential 15


OPEN SQL

Performance adjustments

© 2017 Wipro wipro.com confidential 16


ABAP CDS Views

© 2017 Wipro wipro.com confidential 17


Core Data Services

Code-to-Data Paradigm
Overview Code-to-Data ---- Top-Down Approach (≥ NW AS ABAP 7.40 SP05)

© 2017 Wipro wipro.com confidential 18


Core Data Services

Core Data Service @ ABAP

© 2017 Wipro wipro.com confidential 19


Core Data Services

CDS: Common Basis for Domain-Specific


Frameworks

© 2017 Wipro wipro.com confidential 20


Core Data Services

CDS Views
A Database-oriented programming model is supported better through:

 A new and advanced Open SQL, supporting considerably more of the SQL-92
standard

 New capabilities to define views. Definition capabilities were extended to have a Tight-
Database-Programming-Model by introducing a common set of domain-specific
languages and services for defining and consuming semantically rich data models –
called Core Data Services

 Using HANA Specific Features

© 2017 Wipro wipro.com confidential 21


Core Data Services

Paradigm Changes in Application Programming

© 2017 Wipro wipro.com confidential 22


Core Data Services

Core Data Services (CDS): Building Block for Timeless


Software

Availability of CDS in SAP Platforms

 SAP NetWeaver 7.4 SP05


 SAP HANA SPS6
 SAP Business Suite EHP7 (Suite on HANA)
 S/4HANA
 SAP Business Warehouse 7.3

© 2017 Wipro wipro.com confidential 23


Core Data Services

Core Data Services – A Family of Domain Specific


Languages

© 2017 Wipro wipro.com confidential 24


Core Data Services

Advantages of CDS Views


Property CDS View ABAP View
Arithmetic Operations Yes No

Dynamic Fields Yes No


Buffering Options Yes No
Dynamic Where Clause Yes No

Offset Field Selection Yes No

String Operations Yes No


Reusability Yes No
Flexibility Yes No
Parameters/Defaults Yes No

© 2017 Wipro wipro.com confidential 25


Core Data Services

Code Push-Down Scenarios with CDS

© 2017 Wipro wipro.com confidential 26


Core Data Services

Annotations

© 2017 Wipro wipro.com confidential 27


Core Data Servcies

Annotations in CDS views

© 2017 Wipro wipro.com confidential 28


Core Data Services

Example – CDS Views

View Name

Joining
conditions

© 2017 Wipro wipro.com confidential 29


Core Data Servcies

Parameters in CDS View


 Filter the data during selection process at database
level itself
 No need to put additional filtering (where condition)
at ABAP Layer
 Code to Data shift
 Choose the template
 Define View with Parameters
 Provide the parameter name and parameter type
 Multiple parameters in a CDS View, separated by a
comma.

© 2017 Wipro wipro.com confidential 30


Core Data Servcies

Parameters in CDS View Cont..

© 2017 Wipro wipro.com confidential 31


Core Data Servcies

Consume CDS View in ABAP Program

© 2017 Wipro wipro.com confidential 32


Session 1

CDS Built-in (SQL) Expressions

© 2017 Wipro wipro.com confidential 33


Session 1

CDS Built-in Expressions Overview


*Below is a sample list. Current version is having more options

© 2017 Wipro wipro.com confidential 34


Example: Currency Conversion

Session 1

© 2017 Wipro wipro.com confidential 35


Core Data Servcies

Example: String Function

Sub string Data

© 2017 Wipro wipro.com confidential 36


AMDP(ABAP
MANAGED DATA BASE
PROCEDURES)

© 2017 Wipro wipro.com confidential 37


AMDP

AMDP(ABAP MANAGED DATA BASE PROCEDURES)- Design

Sub string Data

© 2017 Wipro wipro.com confidential 38


AMDP

AMDP- Advantages
Compare Database Procedure as a function stored and executed in the database.
In SAP HANA implementation language is SQLScript.
 Allowing developers to write database procedures directly in ABAP
 Only the AMDP class has to be transported with ABAP transport mechanism.
 AMDP manages SQLScript source code in AS ABAP
 AMDP integrates SQLScript syntax check in ABAP syntax check
 AMDP creates and manages stored procedure runtime objects on HDB in the ABAP AS
database schema

© 2017 Wipro wipro.com confidential 39


AMDP

AMDP- Features
 Static check code and Syntax coloring are provided for embedded SQLScript
 The user can set a Background color for better visibility AMDP methods in the class.
 The User can access other AMDP methods, ABAP dictionary view and ABAP tables in AMDP method.
 AMDP method are called like other regular ABAP methods.
 User can perform detailed analysis of various error during runtime in transaction ST22
 Modification or Enhancement of regular ABAP classes can be done by Users.

© 2017 Wipro wipro.com confidential 40


AMDP

AMDP- Prerequisites

Classes which will act as a container for AMDPs have to implement a so called
Marker Interface IF_AMDP_MARKER_HDB.

© 2017 Wipro wipro.com confidential 41


AMDP

AMDP- Implementation

© 2017 Wipro wipro.com confidential 42


AMDP

AMDP- Call scenarios

© 2017 Wipro wipro.com confidential 43


Thank You
Anversha Shahulhameed

Lead Consultant

© 2017 Wipro wipro.com confidential 44

You might also like