Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  AMDP - ABAP Managed Database Procedures →  AMDP - Methods 

AMDP - Function Implementations

An AMDP function implementation is an AMDP method for implementing an AMDP function as a database function. An AMDP function implementation is indicated as an AMDP method in the implementation part of the class using the addition BY DATABASE FUNCTION of the statement METHOD. There are AMDP table functions and AMDP scalar funktions.

Other versions: 7.31 | 7.40 | 7.54

AMDP Table Functions

There are two types of AMDP table functions:

  • Functions that can only be accessed in other AMDP methods

AMDP table functions for AMDP methods

An AMDP function implementation for an AMDP table function that can only be accessed in AMDP methods is declared in an AMDP class like a regular static method or instance method in any visibility section. An AMDP function implementation like this cannot be detected in the declaration part of the class and the same basically applies as to AMDP procedure implementations with the following differences:

  • The AMDP function implementation must have a return value defined using RETURNING. The data type of the return value must be tabular with a structured row type whose components are elementary. Any table category and table key can be specified for return value.
  • No class-based exceptions can be declared using RAISING in the interface of the AMDP function implementation.
  • In declarations of the AMDP method using the addition AMDP OPTIONS READ-ONLY or in implementations of the AMDP method using the addition OPTIONS READ-ONLY, the AMDP function implementation must be restricted to reads.

The AMDP table function of a AMDP table function can be called from other AMDP methods. It cannot be called in ABAP programs like a regular functional method.


Notes

  • Calls from ABAP programs are not implemented since the results set cannot be restricted directly here by a WHERE condition.

Executable Example

AMDP functions

AMDP Table Functions for CDS Table Functions

The same applies to an AMDP function implementation that implements an CDS table function as to the AMDP table functions for AMDP methods above, with the following differences:

  • An AMDP function implementation for a CDS table function can only be declared in the public visibility section of a static AMDP class. It is not possible in interfaces.
  • The input parameters in the AMDP function implementation are determined by the input parameters of the CDS table function. Their names are used and the ABAP types are derived from their Dictionary types. The input parameters are always elementary and not optional.
  • A return value with the type of a standard table is created with an empty table key named result with a structured row type. The components of the row type are determined by the elements of the CDS table function. Their names are used and the ABAP types are derived from their Dictionary types. The row type corresponds to the structured data type, which the CDS table function represents with respect to ABAP. In the case of a client-specific CDS table function, the client column is also included.

The AMDP table function defined by an AMDP function implementation like this can be used as follows using the CDS entity represented by the CDS table function:

In addition, calls from other AMDP methods are possible. Calls as regular functional methods are not possible in an ABAP program.


Notes

  • The row type of the return value result of an AMDP function implementation for a client-specific CDS table function does not contain a client field, even though this field must be declared in the element list.

  • An AMDP function implementation can only be associated with a single CDS table function.

  • When an AMDP function implementation is created for a CDS table function, it must already exist as an active function. When a new CDS table function is activated, an empty AMDP table function is created in the database. This function raises an exception if a non-AMDP access is performed. When the CDS table function is accessed by the ABAP runtime environment for the first time (for example, using ABAP SQL), the AMDP function implementation implements the empty AMDP table function. Other frameworks that evaluate CDS entities using their annotations, however, can also cause the AMDP table function to be implemented. It is possible to access the table function in a native way only after the implementation.

Executable Example

AMDP functions

AMDP Scalar Functions

An AMDP is declared in an AMDP class like a regular static method or instance method in any visibility section. An AMDP function implementation like this is unknown in the declaration part of the class and the same basically applies as to AMDP table functions for AMDP methods with the following differences:

  • The data type of the return value is elementary.
  • The data types of input parameters must also be elementary.
  • No class-based exceptions can be declared using RAISING in the interface of the AMDP function implementation for AMDP scalar functions.

The AMDP scalar function defined using an AMDP function implementation like this can be used in other AMDP methods in accordance with the rules for scalar functions.


Notes

  • These functions can be used in non-AMDP-managed database procedures or database functions, like any database scalar function, but this is not recommended.

  • It is possible for an AMD scalar function to specify the database-specific option DETERMINISTIC after OPTIONS. This buffers the result of the function for the duration of a query.

Executable Example

AMDP functions