ABAP CDS table functions define table functions that are implemented natively on the database and can be called in CDS. As such, they support the HANA platform code pushdown capabilities in ABAP CDS.
A CDS table function is defined using the ABAP CDS statement DEFINE TABLE FUNCTION and can be used as the data source in Open SQL read statements.
Each CDS table function includes the following components:
The actual CDS entity of the table function that is generated in the ABAP Dictionary
The CDS table function implementation (ABAP class library)
In contrast to the CDS views, the CDS table functions can be implemented using Native SQL. This implementation is done within an AMDP method of an AMDP class and is managed as an AMDP function by the AMDP framework in the database system.
The name of the implementing AMDP method can only be specified in a single CDS table function (1: 1 relation).
Table Function Definition
In the following listing, a client-specific ABAP CDS table function TAB_FUNCTION_EXAMPLE is defined using the DDL syntax. This table function declares two input parameters clnt (with the predefined value: #CLIENT) and carrid, and a list of elements that provide the return values of the AMDP method that implements the table function. The table function is associated with the AMDP class CL_EXAMPLE_AMDP, where the method GET_FLIGHTS is used to implement the table function.
@ClientDependent: true @AccessControl.authorizationCheck: #NOT_REQUIRED define table function TAB_FUNCTION_EXAMPLE with parameters @Environment.systemField: #CLIENT clnt:abap.clnt, carrid : s_carr_id returns { client : s_mandt; carrname : s_carrname; connid : s_conn_id; cityfrom : s_from_cit; cityto : s_to_city; } implemented by method CL_EXAMPLE_AMDP=>GET_FLIGHTS;
Table Function Implementation
The public ABAP class (AMDP class) in this example provides the AMDP method get_flights, which serves as the implementation of thetable function tab_function_example. As with any other AMDP class, cl_example_amdp must implement the marker interface IF_AMDP_MARKER_HDB. The AMDP method get_flights implements the data selection using Native SQL code.
class cl_example_amdp definition public. public section. interfaces IF_AMDP_MARKER_HDB. class-methods get_flights for table function tab_function_example. protected section. private section. endclass. class cl_example_amdp implementation. method get_flights by database function for hdb language sqlscript options read-only using scarr spfli. RETURN SELECT sc.mandt as client, sc.carrname, sp.connid, sp.cityfrom, sp.cityto FROM scarr AS sc INNER JOIN spfli AS sp ON sc.mandt = sp.mandt AND sc.carrid = sp.carrid WHERE sp.mandt = :clnt AND sp.carrid = :carrid ORDER BY sc.mandt, sc.carrname, sp.connid; endmethod. endclass.
See also: Editing DDL Source Code
See also: Debugging AMDPs