Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Native SQL 

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 procedure) is a procedure written in a database-specific language ( Native SQL, SQL Script, L, ...) implemented in an AMDP method of an AMDP class.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • 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 SQL Script 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 SQL Script 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 ABAP 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 section 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 obsolete predefined data types DF16_SCL or DF34_SCL in ABAP Dictionary.
  • Only input parameters can be flagged as optional and every optional parameter must have a replacement parameter declared using DEFAULT. Only literals or constants can be specified as replacement parameters.
  • Parameter names:
  • Parameter names cannot start with the characters "%_".
  • The parameter name connection can only be used for an input parameter of type DBCON_NAME, if the name of the database connection can be passed to the input parameter.
  • The parameter name client is reserved for future enhancements.
  • The parameter name endmethod is not permitted.
  • With RAISING the exception classed listed under AMDP - exception classes can be specified to handle these classes for a call. Other exceptions cannot be handled. No non-class-based exceptions can be created using the addition EXCEPTIONS.

The following restrictions apply to method implementation:

  • DDL statements are not permitted for creating, changing or deleting database objects.
  • Local temporary database objects cannot be accessed.
  • Database commits and rollbacks cannot be executed. The statements COMMIT and ROLLBACK in particular are not permitted. LUWs should always be handled in the ABAP program, to ensure data consistency between procedures.
  • Write access to database tables, for which SAP buffering is activated, is not permitted.

An AMDP method is indicated as an AMDP method in the implementation section 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. An AMDP method cannot be empty.

Further restrictions may apply depending on the programming language of the database system and these are discussed in the corresponding sections:


Note

It is strongly recommended that only the character set 7-bit-ASCII is used when implementing an AMDP method.

AMDP Polymorphism

Both interface methods and redefined methods inherited from superclasses can become AMDP in the implementation, provided that the above prerequisites are met and the class contains the appropriate tag interface. If a subclass contains a tag interface, this also applies to its subclasses. If an interface contains a tag interface, this also applies to classes that implement this interface.

Constructors cannot be implemented as AMDP methods.

AMDP Calls

An AMDP method is called in an ABAP program in the same way as any other ABAP Objects method. 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. Execution is performed 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.

Once a database procedure (managed using AMDP) has been created on the database, this procedure can be called from other database procedures using the database syntax (provided that this is permitted by the database). These can be AMDP procedures (or database procedures) that are not managed by AMDP. If an AMDP procedure calls another procedure, this procedure must be specified after addition USING of the calling method.


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 calling program of an AMDP method from ABAP, it is usually clear 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 calling program. 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.

  • Generally, the database procedures managed using AMDP are called using AMDP methods only. If, in exceptional cases, these database procedures are called from other database procedures not managed using AMDP, all required database objects must be made available. This can be done using the public methods of the documented class CL_AMDP_RUNTIME_SERVICES.

AMDP BAdIs

In addition to the option of implementing BAdI methods of a normal BAdI as AMDP methods and making these methods callable by using CALL BADI, it is also possible to create special AMDP BAdIs. A AMDP BAdI is a BAdI, which is labeled accordingly in BAdI Builder and has the following properties:

  • Definition and implementation
  • An AMDP BAdI does not currently have any filters.
  • Every BAdI method of an AMDP BAdI must be an AMDP method.
  • Every AMDP method must be implemented for the same database system.
  • Call BAdI methods
  • The AMDP procedures created on the database of an AMDP BAdI can be called here (like all AMDP procedures) from other AMDP methods in the same database system. These AMDP procedures are specified using the name of a BAdI implementation class. The usage must be declared after the addition USING of the calling method.
In both cases, execution is performed in accordance with the rules of the enhancement concept and the corresponding switch in Switch Framework. If no enhancement is available, the mandatory fallback implementation class is implemented.


Note

AMDP BAdIs are primarily used to execute calls of AMDP procedures from AMDP procedures - in accordance with the rules of the switch-based enhancement concept. Although switch-based calls of AMDP methods can be made from ABAP programs without AMDP BAdIs, these calls can only be made from AMDP procedures for AMDP methods of AMDP BAdIs. The AMDP framework ensures that the relevant database procedure for the current database switch setting is created on the database.

AMDP Database Connections

The implementation of an AMDP method is always executed on the SAP standard database. By default, the call is made using the standard database connection. The database connection to the SAP standard database can also be specified explicitly (optional), which enables the use of service connections.

To specify the database connection explicitly, an input parameter (with the predefined name connection) can be declared for an AMDP method. This parameter must be of type DBCON_NAME. When the AMDP method is called, the following values can be passed to the parameter to specify the database connection:

  • When the initial value or the value "DEFAULT" is passed, the standard database connection is used.
  • When a name "R/3*name" is passed, which consists of the prefix "R/3*" (uppercase characters) and a user-defined name "name" (case sensitive), a service connection of this name is used in open SQL (similar to when addition CONNECTION is used). The names "R/3*AMDP_SYNC" and "R/3*AMDP_ADBC" are exceptions. They are used by the AMDP framework itself.

All other names raise an exception.


Notes

  • The parameter connection cannot be used to implement the AMDP method.

  • Service connections for the SAP standard database are useful for performing operations in a database LUW, which does not depend on the LUW standard connection.

  • A maximum of 16 database connections can be opened at the same time for a work process. This means a maximum of 15 service connections is possible, in addition to the standard database connection.

Examples

See AMDP - Examples.

Continue

METHOD - BY DATABASE PROCEDURE

AMDP - Exception Classes

AMDP - Examples