You are on page 1of 11

ABAP Managed Database Procedures

Code-to-Data with AS ABAP 7.4


ABAP Managed Database Procedures
Stored Procedures in ABAP < 7.40 SP05

Top-Down Stored Procedures l_ddl_command =


Procedures created by ABAP code using |create procedure dbproc( | &
| in i_param1 integer, | &
native SQL DDL statements
| inout ch_param3 nvarchar (20) ) | &
Lifecycle management in ABAP |language sqlscript | &
|sql security invoker as | &
With ADBC: flexible, error-handling,
|begin | &
| select top :i_param1 * | &
Consumption in ABAP | from sys.dummy; | &
| ch_param3 := 'Success'; end; |.
im_sql_handle->execute_ddl(
l_ddl_command ).
Bottom-Up Stored Procedures in
ABAP 7.4 < SP05
Easy to consume in ABAP code CALL DATABASE PROCEDURE db_proxy
EXPORTING in_date = in_date
Own lifecycle management & transport in_sel = in_sel
IMPORTING out_itms = out_itms.
No protection using ABAP packages

2013 SAP AG. All rights reserved. Public 3


ABAP Managed Database Procedures
Need For A New Way of Implementing SAP HANA Database Procedures

Like ABAP code, AMDP methods are fully managed on the ABAP server
Bottom-Up Lifecycle Top-Down Lifecycle
AS ABAP

AS ABAP
Stored HANA ABAP Standard ABAP
Procedure Transport- Managed Database Transport
Proxy Container Procedure (CTS)

expose transport deploy


SAP HANA

SAP HANA
Stored Stored
Delivery Unit Procedure
Procedure

SAP HANA Database Procedures ABAP Managed Database Procedures

ABAP server as master for editing, activating, transportation, and lifecycle management of
ABAP code and database procedures.

2013 SAP AG. All rights reserved. Public 4


ABAP Managed Database Procedures
AMDPs: Integration of Database Procedures Into ABAP

Standard ABAP class methods are used as containers for the implementation of AMDPs

CLASS CL_AMDP_SAMPLE DEFINITION.


PUBLIC SECTION.
INTERFACES IF_AMDP_MARKER_HDB.
...
PRIVATE SECTION.
METHODS execute IMPORTING VALUE(it_param) TYPE type1
EXPORTING VALUE(et_param) TYPE type2.
ENDCLASS.
CLASS CL_AMDP_SAMPLE IMPLEMENTATION.
...
METHOD execute BY DATABASE PROCEDURE .
Method container
-- SQLScript code for AMDP
ENDMETHOD.
ENDCLASS.

2013 SAP AG. All rights reserved. Public 5


ABAP Managed Database Procedures
Class Definition

Prerequisites in class definition


CLASS CL_AMDP_SAMPLE DEFINITION.
Classes with AMDPs must use
PUBLIC SECTION.
interface IF_AMDP_MARKER_HDB INTERFACES IF_AMDP_MARKER_HDB.
All AMDP method parameters must * Only ABAP code possible:
be passed by value (like RFC) METHODS process
IMPORTING it_param TYPE type1
All AMDP parameters must be tables EXPORTING et_param TYPE type2.
with elementary components or * ABAP code or SQLScript possible:
scalar types METHODS execute
IMPORTING VALUE(it_param) TYPE type1
EXPORTING VALUE(et_param) TYPE type2.

ENDCLASS.

2013 SAP AG. All rights reserved. Public 6


ABAP Managed Database Procedures
Class Implementation

Extended method implementation


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

2013 SAP AG. All rights reserved. Public 7


ABAP Managed Database Procedures
SQLScript Example

Accessing ABAP Dictionary tables, ABAP Dictionary views, and other AMDP methods in
an AMDP method
METHOD execute BY DATABASE PROCEDURE FOR HDB
LANGUAGE db_language OPTIONS READ-ONLY
USING T000 [TABLE]
CL_AMDP_CONCEPT=>GET_RESULT.
-- Select a scalar value:
declare lv_field type NVARCHAR(1);
select field from T000 into lv_field where mandt = '000';

-- Select multiple values in different columns:


lt_result = select field1 field2 from [Table]
where mandt = '000'
and field3 in :it_param;
-- Call another AMDP method:
CALL "CL_AMDP_CONCEPT=>GET_RESULT" (:it_param, :lt_result, :et_param );
ENDMETHOD.

2013 SAP AG. All rights reserved. Public 8


ABAP Managed Database Procedures
Execution of AMDP Methods in ABAP and SAP HANA

An AMDP method is called like any


ABAP method. ...
METHOD process.
Several SAP HANA repository objects me->execute(
are created: EXPORTING it_param = it_param
IMPORTING et_param = et_param
During the first call of the AMDP method ).
In the SAP<SID> schema ENDMETHOD.

Runtime:
AMDP methods are executed like static
methods, even if they are defined as
instance methods
When an AMDP is processed, the ABAP
stack calls the corresponding database
procedure in SAP HANA

2013 SAP AG. All rights reserved. Public 9


ABAP Managed Database Procedures
Demo SQL Script static code check

Icon indicates line with error

Detailed error description


(mouse over)

Summary of errors

2013 SAP AG. All rights reserved. Public 10


ABAP Managed Database Procedures
Demo Runtime Errors in AMDP methods

Like any other ABAP method, an AMDP method call might fail and the failure is traced in ST22.

Special section for AMDP

Error position in AMDP


method

HANA call stack

2013 SAP AG. All rights reserved. Public 11

You might also like