Vous êtes sur la page 1sur 25

SAP HANA and Big Data Community

HANA Expert Series:


AMDP ABAP Managed Database Procedure Overview (1/2)

September 2015
SAP SDC India
Vipin Nagpal
Session Agreement

Please participate
by asking questions !?!

During the session


Use the chat
Unmute yourself by pressing *6
The more people share, the more you have
Here you have the chance to ask the
expert

After the session


Use the SAP HANA and Big Data
Community
Volunteer to deliver a session.
Send an abstract to
darren.louie@sap.com
and become a HANA Hero

2015 SAP SE or an SAP affiliate company. All rights reserved. Internal 2


Agenda ABAP managed database procedure overview (1/2)

Code Push down technique

Bottom up Vs Top Down approach

AMDP syntax

Error / Exception handling in AMDP Method

Debugging in AMDP

Use case

Q&A

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


How can my ABAP code benefit from SAP HANA?
The new paradigm

Calculation
AS ABAP

Data to Code Code to Data

SAP HANA
Database
Calculation

Code pushdown means delegating data intense calculations to the


database layer

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


NW AS ABAP 7.4 SP 2 - Bottom-Up

Bottom-Up
LM
AS ABAP

Stored Procedure HANA


External Views
External Views Proxy Proxy
Stored Transportcontainer

exposing exposing transporting


SAP HANA

Hana Views Stored Procedures Delivery Unit


EPM Datamodel Modeled Views

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


NW AS ABAP 7.4 SP5 Top Down

Top-Down
LM
AS ABAP

ABAP Managed
CDS Views Stored Procedure Standard ABAP
External Views Stored
(AMDP)Proxy Transport (CTS)

deploy deploy
SAP HANA

Hana Views Stored Procedures


EPM Datamodel Modeled Views

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


New way of using HANA Database Procedures in ABAP
ABAP Managed Database Procedure (AMDP)

ABAP server as sole Master for developing, Top-Down-Approach


managing and calling database procedures Lifecycle

AS ABAP
AMDP provided as methods of global
Standard ABAP
classes marked with tag interfaces AMDP
Transport (CTS)
(aka AMDP class)
HANA Database procedure created at the
create
first call of the AMDP method

SAP HANA
Transport as any other ABAP class
Database
Only ABAP Development Tools required Procedure

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


ABAP Managed Database Procedures
Class Implementation

Extended method implementation syntax: BY CLASS CL_AMDP_SAMPLE


DATABASE PROCEDURE IMPLEMENTATION.
Indicates method body contains database-specific code METHOD execute
not executable on the ABAP server BY DATABASE PROCEDURE
Database platform FOR db_platform
(only SAP HANA supported as of now) LANGUAGE db_language
[OPTIONS READ-ONLY]
Database procedure language
USING name1 name2 etc..
(for example, SQLScript)
Used ABAP Dictionary tables, Dictionary views, and -- Write SQLScript code here.
other AMDP methods select * from dummy;
Native SAP HANA SQLScript source code ENDMETHOD.
ENDCLASS.

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


AMDP on HANA at a Glance
Class Definition

Marker interface
CLASS CL_AMDP_SAMPLE DEFINITION. for HDB

PUBLIC SECTION.
INTERFACES IF_AMDP_MARKER_HDB.
METHODS process
IMPORTING it_param TYPE type1
Only ABAP code
possible
EXPORTING et_param TYPE type2. specific parameter
interface required
METHODS execute
IMPORTING VALUE(it_param) TYPE type1
ABAP or SQLScript EXPORTING VALUE(et_param) TYPE type2.
code possible CHANGING VALUE(ch_param) TYPE type3

ENDCLASS.

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


AMDP on HANA at a Glance
Class Implementation

CLASS CL_AMDP_SAMPLE IMPLEMENTATION.


METHODS process. Marker for
* ABAP source code here
AMDP method
...
ENDMETHOD.
METHOD execute BY DATABASE PROCEDURE
Database platform FOR HDB Database language
LANGUAGE SQLScript
[OPTIONS READ-ONLY] Database-specific
List of used DDIC options
entities and AMDPs
USING name1 name2 etc..
--Write your native SQLScript coding here.
select * from dummy;
...
ENDMETHOD. SQLScript
ENDCLASS. source code

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


2015 SAP AG or an SAP affiliate company. All rights reserved. 11
2015 SAP AG or an SAP affiliate company. All rights reserved. 12
Limitations of AMDP

The parameters have to meet the following prerequisites:


Exporting, importing and changing parameters are allowed
Methods with returning parameters cannot be implemented as AMDPs
Method parameters have to be tables or scalar types
Method parameters have to be passed as values

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


ABAP Managed Database Procedures (AMDP)
Call AMDP Methods: Error Handling
Like any other ABAP method, an AMDP method call might fail

Typical runtime errors


Invalid parameters at runtime (User error)
Syntax errors in SQLScript source code after changes in used objects (User error)
Errors during (re-)creation of database procedures (Internal error)

AMDP provides detailed ABAP short dump information


SQLScript error message evaluation
SQLScript call stack
Special ST22 section for AMDP methods

Error and short dump handling for AMDP methods feels almost like ABAP

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


ABAP Managed Database Procedures (AMDP)
Call AMDP Methods: Analyze Short Dumps

Special section for AMDP


Error position in AMDP
method

HANA call stack

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


2015 SAP AG or an SAP affiliate company. All rights reserved. 16
Debugging AMDP (Four step Process)

Set a breakpoint in DB procedure body in HANA Schema SAP<SID>.

Create debug configuration

External Debugging: Attach the SQL Script debugger

Execution of the ABAP report from where you are consuming AMDP method.

OSS note : 1942471 gives detail about required authorization.

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


AMDP debugging AS ABAP 740 SP5 and higher

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


Enterprise Procurement Model (EPM)

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


Use Case: Top and flop customers based on sales order amount

Use case functional description


Identify 10 top and flop customers based on sales order gross amount. This report will look at customer sales order
historical data and preform aggregate sum on sales order gross amount. Result set will be sorted on ascending and
descending to get top and flop customers.

Areas of Improvement in classical Design


In traditional approach, all data related to customer sales orders passed to application server. Calculation logic has
been performed in application server which is time consuming.

Volume of data
This report was tested with half million sales order data.

Code Push down Technique used


AMDP (ABAP Managed Database Procedure) has been used as code push down technique to improve performance
of report. Aggregate sum calculation logic has been performed at database layer.

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


After and Before Comparison

Before After

% improvement
93% improvement in execution time was noticed with code push down Technique.

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


Q&A

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


Reference used while preparing these slides

SCN

SAP internal Portal

Open.sap.com

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


Thank you

Presenter: Vipin Nagpal (I065360)


SDC India
Email : v.nagpal@sap.com

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


2015 SAP AG oder ein SAP-Konzernunternehmen.
Alle Rechte vorbehalten.

Weitergabe und Vervielfltigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrckliche schriftliche
Genehmigung durch SAP AG nicht gestattet. In dieser Publikation enthaltene Informationen knnen ohne vorherige Ankndigung gendert werden.

Einige der von der SAP AG und ihren Distributoren vermarkteten Softwareprodukte enthalten proprietre Softwarekomponenten anderer Softwareanbieter.

Produkte knnen lnderspezifische Unterschiede aufweisen.

Die vorliegenden Unterlagen werden von der SAP AG und ihren Konzernunternehmen (SAP-Konzern) bereitgestellt und dienen ausschlielich zu Informationszwecken.
Der SAP-Konzern bernimmt keinerlei Haftung oder Gewhrleistung fr Fehler oder Unvollstndigkeiten in dieser Publikation. Der SAP-Konzern steht lediglich fr Produkte
und Dienstleistungen nach der Magabe ein, die in der Vereinbarung ber die jeweiligen Produkte und Dienstleistungen ausdrcklich geregelt ist. Keine der hierin
enthaltenen Informationen ist als zustzliche Garantie zu interpretieren.

SAP und andere in diesem Dokument erwhnte Produkte und Dienstleistungen von SAP sowie die dazugehrigen Logos sind Marken oder eingetragene Marken der SAP
AG in Deutschland und verschiedenen anderen Lndern weltweit.

Weitere Hinweise und Informationen zum Markenrecht finden Sie unter http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark.

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