Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

AMDP – ABAP Managed Database

Procedures
Sounds like some kind of jargon, yes? Actually, it is what it says. It is a
Database Procedure which is managed by ABAP i.e. you can create, change
or delete AMDPs using ABAP Development Tools in Eclipse. This also means
that AMDPs can be transported using ABAP Transport.

AMDP is basically a method of a global class which is implemented by a Database


Procedure in Language SQLSCRIPT.

How to create AMDP?

1. Create a global class

2. Add AMDP marker interface IF_AMDP_MARKER_HDB

3. Create a method definition

4. Implement the method using DATABASE PROCEDURE

1. Create a global class

AMDP method can only be created in a global class. If you try to create it in
Local Class, you will get below error.
So create a global class in Eclipse.
2. Add AMDP marker interface
IF_AMDP_MARKER_HDB

Add interface IF_AMDP_MARKER_HDB. Remember, interfaces can only be


added in PUBLIC SECTION.

3. Create a method definition

An AMDP Method can be defined like a regular static/instance method in


any visibility section i.e. public, private, or protected. However, it does have
below restrictions for the parameters –

Only Variables and Tables are allowed as


parameters. We can not use structures or nested
tables.

 Generic types can not be used for parameters. For example Type Any can not be
used.

 Only elementary data types and table types with a structured row type can be used.

 The table type components must be elementary data types and it can not have
elements which are table types.
Additional restrictions on method parameters

 Only pass by value can be used. Pass by reference is not permitted. Using
VALUE keyword for all parameters is required.

 RETURNING parameters are not allowed. We can use EXPORTING or


CHANGING to receive the values.

 Only input parameters can be flagged as optional with a DEFAULT value


( literals/constants )

 In RAISING clause, only class based exceptions are allowed from a specific
exception list.

 Parameter names can not start with %_. I like this rule as it does not affect me.

 Some keywords like connection, client, endmethod are reserved. Do not use such
names for parameters.

Allowed Exception List

CX_ROOT
|
|--CX_DYNAMIC_CHECK
|
|--CX_AMDP_ERROR
|
|--CX_AMDP_VERSION_ERROR
| |
| |--CX_AMDP_VERSION_MISMATCH
|
|--CX_AMDP_CREATION_ERROR
| |
| |--CX_AMDP_DBPROC_CREATE_FAILED
| |
| |--CX_AMDP_NATIVE_DBCALL_FAILED
| |
| |--CX_AMDP_WRONG_DBSYS
|
|--CX_AMDP_EXECUTION_ERROR
| |
| |--CX_AMDP_EXECUTION_FAILED
| |
| |--CX_AMDP_IMPORT_TABLE_ERROR
| |
| |--CX_AMDP_RESULT_TABLE_ERROR
|
|--CX_AMDP_CONNECTION_ERROR
|
|--CX_AMDP_NO_CONNECTION
|
|--CX_AMDP_NO_CONNECTION_FOR_CALL
|
|--CX_AMDP_WRONG_CONNECTION
(Source : https://help.sap.com/doc/abapdocu_740_index_htm/7.40/en-US/index.htm?file=abenamdp.htm )

Considering all the restrictions, AMDP method can be defined as below.

4. Implement the method using


DATABASE PROCEDURE

The syntax to implement ADMP method is as below –


Important

 Every AMDP method will have below addition. READ-ONLY is only the optional
addition and is used for methods that only read the data.

o BY DATABASE PROCEDURE

o FOR HDB

o LANGUAGE SQLSCRIPT

o READ-ONLY
 It is also mandatory to specify all the database objects and other AMDP methods
that are used within the SQLSCRIPT code.

 No ABAP statements can be written in the method code.

 AMDP methods do not have any implicit enhancement options.

Restrictions

 DDL statements that create/change/delete database objects can not be used.

 The statements COMMIT and ROLLBACK are not permitted


 Write access to database tables, for which SAP buffering is activated, is not
permitted.
Once again, the class definition and implementation will look like below.

Refer post Working With Eclipse [2] : Useful Eclipse Preferences to set up different
background color for SQLSCRIPT code

Code Reference
CLASS zjp_simple_admp_class DEFINITION
PUBLIC FINAL CREATE PUBLIC .

PUBLIC SECTION.
INTERFACES : if_amdp_marker_hdb.
TYPES : tt_flights TYPE STANDARD TABLE OF sflight.
METHODS : get_flights IMPORTING VALUE(iv_carrid) TYPE sflight-carrid
EXPORTING VALUE(et_flights) TYPE tt_flights.

ENDCLASS.

CLASS zjp_simple_admp_class IMPLEMENTATION.

METHOD get_flights BY DATABASE PROCEDURE


FOR HDB
LANGUAGE SQLSCRIPT
USING sflight.

et_flights = select * from sflight WHERE carrid = :iv_carrid;

ENDMETHOD.

ENDCLASS.

You might also like