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

AMDP - ABAP Managed Database

Procedures
ABAP Managed Database Procedures are a framework for managing and calling stored
procedures or database procedures in AS ABAP. An ABAP Managed Database Procedure
(or AMDP is a procedure written in its database-specific language (Native SQL, SQLScript, ...)
implemented in an AMDP method of an AMDP class.

 AMDP Classes

 AMDP Methods

 AMDP Calls

Notes
 The ABAP Development Tools (ADT) are better suited for the editing of database procedures
in AMDP methods than Class Builder in ABAP Workbench. This means that AMDP classes
can only be edited with the ABAP Development Tools (ADT).

 The AS ABAP logged on to the database system using its work processes requires the
correct authorizations to manage database procedures using AMDP. Missing authorizations
can be detected using transaction SICK.

 If the current database of an AS ABAP is an SAP HANA database and ABAP programs
access SQLScript procedures used to swap out code from ABAP programs to the database,
ABAP Managed Database Procedures are the replacement technology for database
procedure proxies. Database procedure proxies are still recommended when using a
secondary database connection to access SQLScript procedures that exist in a different SAP
HANA database.

 Currently, AMDP only supports database procedures from the SAP HANA database. In
principle, however, AMDP is designed so that stored procedures from other database
systems can also be supported.

Programming Guideline
The programming guideline Use Open SQL is particularly relevant for AMDP too. The use of AMDP
is not recommended if the same task can be achieved using Open SQL (or CDS). The
example AMDP, Comparison with Open SQL demonstrates how a database access not
programmed well in Open SQL can often be optimized using an improved use of Open SQL,
removing the need to use AMDP in these cases. AMDP should be used only if it enables database-
specific functions to be accessed that do not exist in Open SQL (see the example for Currency
Conversion) or if large process flows or analyses that incur repeated transports of large amounts of
data between the database and the application server can be swapped out.

AMDP Classes
An AMDP class is a global class in the Class Library that contains one or more of the following tag
interfaces:

 IF_AMDP_MARKER_HDB for the SAP HANA database

The names of the interfaces all start with IF_AMDP_MARKER and a suffix indicates the database
system for which the ABAP Managed Database Procedures can be implemented in AMDP methods
of the class.
An AMDP class can contain both regular methods and AMDP methods. It can contain one or more
AMDP methods for each database system specified by a tag interface.

AMDP Methods
An AMDP is declared in an AMDP class like a regular static method or instance method in
any visibility section. An AMDP method cannot be identified as an AMDP method in the declaration
part of the class. The following restrictions apply, however, with respect to the parameter interface:

 The typing of the parameters cannot be generic. Only elementary data types and table


types with a structured row type can be used. The row type of a tabular type can only contain
elementary data types as components

 A parameter cannot be typed with a data type that references one of the predefined data
types DF16_SCL or DF34_SCL in ABAP Dictionary.

 The parameters must be declared using VALUE for pass by value. Pass by reference is not


permitted.

 Return values cannot be declared using RETURNING.

 Only input parameters can be flagged as optional and every optional parameter must have a
replacement parameter declared using DEFAULT. Only constants can be specified as
replacement parameters.

 Parameter names cannot start with the characters "%_". The parameter
names client and connection are reserved for future enhancements. The parameter
name endmethod is not permitted.

 No non-class-based exceptions can be created using the addition EXCEPTIONS. Class-


based exceptions can be specified using RAISING, however there are currently no catchable
exceptions among the database procedures and they always produced a runtime error.

An AMDP method is indicated as an AMDP method in the implementation part of the class using the
addition BY DATABASE PROCEDURE of the statement METHOD. At the same time, the database
system where the method is used and the programming language of the database system used to
implement the method are also defined. Furthermore, the database objects of the current database
schema must be declared that are accessed in the AMDP. If possible, the syntax check is performed
on the basis of this information.
Both interface methods and redefined methods inherited from superclasses can become AMDP in
the implementation, as long as the class contains the appropriate tag interface. Constructors cannot
be implemented as AMDP methods.
Further restrictions may apply depending on the programming language of the database system and
these are discussed in the corresponding sections:

 SQLScript for the SAP HANA Database

AMDP Calls
An AMDP method is called like any other method in ABAP Objects. This requires, however, that the
central database of the current AS ABAP is managed by the database system for which the AMDP
method is implemented. If not, a runtime error is produced.
Before the method is called for the first time, the ABAP runtime environment creates the procedure
implemented in the AMDP method in the database system of the central AS ABAP database or
updates any existing database procedure. The method is executed in the database system and the
interface parameters are passed from the Native SQL interface to the database system or applied by
the database system itself.

Notes
 It is recommended that AMDP methods that are not to be called from the AMDP methods of
other classes are created as private methods of an AMDP class and that they are called in a
regular method (specified by the central AS ABAP database. In database systems that do
not support AMDP, a regular method can be created using an alternative implementation in
Open SQL or Native SQL.

 For the caller of an AMDP method, it is usually transparent whether the method is an AMDP
method and in which database system it is executed. For this reason, the implementation of
the method must ensure that the interface parameters are returned in a format expected by
the caller. This is particularly important for ABAP types that do not have a corresponding
type in the type system of the database system. These types must either be forbidden in the
interface or an appropriate casting must take place in the procedure.

You might also like