SAP AMDP FUNCTION METHODS



Get Example source ABAP code based on a different SAP table
  



ABAP_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. AMDP table functions and AMDP scalar functions can be implemented.
ITOC

AMDP Table Functions
There are the following 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 AB_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 identified 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.
In addition to the return value, the AMDP function implementation can have elementary and tabular input parameters, but no 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.
BEGIN_SECTION VERSION 5 OUT
The AMDP function implementation must be restricted to reads 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,
END_SECTION VERSION 5 OUT
The AMDP function implementation cannot 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.



Latest notes:

Calls from ABAP programs are not possible since the result set cannot be restricted using a WHERE condition.
NON_V5_HINTS
Calls from non-AMDP-managed database procedures or database functions are possible - like for any database table function - but not recommended.
ABAP_HINT_END

ABAP_EXAMPLE_ABEXA
AMDP functions
ABAP_EXAMPLE_END

AMDP Table Functions for CDS Table Functions
The same rules apply to an AMDP function implementation that implements an CDS table function as to the AMDP table functions for AMDP methods (described 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 addition FOR TABLE FUNCTION must be used for the declaration. This addition 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 represented by the CDS table function. In the case of a client-dependent 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 AB-SQL read statements in ABAP.
as a data source of CDS view entities in the CDS DDL of ABAP CDS .
as a data source of ABAP_CDS_V1_VIEWS in the CDS DDL of ABAP CDS .
In addition, calls from other AMDP methods are possible. Calls as regular functional methods are not possible in an ABAP program.



Latest notes:

The row type of the return value result of an AMDP function implementation for a client-dependent 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 linked with a single CDS table function.
When an AMDP function implementation is created for a CDS table function, the CDS table function 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 framework for the first time (for example, using AB_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.
NON_V5_HINTS
Calls from non-AMDP-managed database procedures or database functions are possible - like for any database table function - but not recommended.
ABAP_HINT_END

ABAP_EXAMPLE_ABEXA
AMDP functions
ABAP_EXAMPLE_END

AMDP Scalar Functions
There are the following types of AMDP scalar functions:
Functions that can only be accessed in other AMDP methods.
Functions that implement CDS scalar functions and that can be used in operand positions of CDS entities.

AMDP Scalar Functions for AMDP Methods
An AMDP function implementation 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 identified as such in the declaration part of the class and the same rules apply as to AMDP table functions for AMDP methods (described above) 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.



Latest notes:

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. For further details, see topic TITLE .
NON_V5_HINTS
These functions can be used in non-AMDP-managed database procedures or database functions, like any database scalar function, but this is not recommended.
ABAP_HINT_END

ABAP_EXAMPLE_ABEXA
AMDP functions
ABAP_EXAMPLE_END

AMDP Scalar Functions for CDS Scalar Functions
The same rules apply to an AMDP function implementation that implements a CDS scalar function as to the AMDP scalar functions for AMDP methods (described above), with the following differences:
An AMDP function implementation for a CDS scalar 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 addition FOR SCALAR FUNCTION must be used for the declaration. This addition flags the AMDP function implementation as an implementation of a CDS scalar 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 scalar function using the statement DEFINE SCALAR FUNCTION in the ABAP CDS CDS DDL:
The input parameters in the AMDP function implementation are determined by the input parameters of the CDS scalar 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 an elementary data type named result is created. Its data type is derived from the CDS scalar function definition.
An AMDP scalar function cannot be called in ABAP like a regular method. It cannot be used as a functional method in a functional method call. Calls from other AMDP methods are not possible. AMDP scalar functions for CDS scalar functions can only be accessed using the name of their CDS entity, that is, the name of the CDS scalar function definition.
The AMDP scalar function defined by an AMDP function implementation like this can be used in operand positions of a CDS view entity in the CDS DDL of ABAP CDS .




Latest notes:

An AMDP function implementation can only be linked with a single CDS scalar function.
When an AMDP function implementation is created for a CDS scalar function, the CDS scalar function definition must already exist as an active function. When a new CDS scalar function definition is activated, an empty AMDP scalar function is created in the database. This function raises an exception if a non-AMDP access is performed. When the CDS scalar function is accessed by the ABAP runtime framework for the first time, the AMDP function implementation implements the empty AMDP scalar function. It is possible to access the scalar function in a native way only after the implementation.
NON_V5_HINTS
Calls from non-AMDP-managed database procedures or database functions are, like any database scalar function , possible but not recommended.
ABAP_HINT_END