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
- Functions that implement CDS table functions that can be accessed in ABAP SQL
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.
- Alongside the return value, the AMDP function implementation can have elementary and tabular
input parameters, but cannot have
input/output parameters or
output parameters. The special input parameter
connection
is not allowed.
- 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 function implementation can be called in ABAP like a regular method and cannot be used as a functional method in a functional method call.
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.
- Calls from non-AMDP-managed database procedures or database functions are, like any database table function, possible but not recommended.
Executable Example
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.
- A special form of the statement
CLASS-METHODS
with the additionFOR TABLE FUNCTION
must be used for the declaration. This form flags the AMDP function implementation as an implementation of a CDS table function.
- The parameter interface of the AMDP function implementation is not declared using the statement
CLASS-METHODS
. Instead it is generated in accordance with the associated CDS table function using the statement DEFINE TABLE FUNCTION in the ABAP CDS CDS DDL:
- 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:
- as a data source of ABAP SQL read statements in ABAP
- as a data source of CDS views in the ABAP CDS CDL DDL.
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.
- Calls from non-AMDP-managed database procedures or database functions are, like any database table function, possible but not recommended.
Executable Example
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.
- An AMDP scalar function can be called in ABAP like a regular method and can be used as a functional method in a functional method call.
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
afterOPTIONS
. This buffers the result of the function for the duration of a query.