Show TOC

ABAP CDS Table FunctionsLocate this document in the navigation structure

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.

Defining ABAP CDS Table Functions

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)

Note

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.

Defining and Implementing CDS table functions
Figure 1: Defining and Implementing CDS table functions
Note

The name of the implementing AMDP method can only be specified in a single CDS table function (1: 1 relation).

Example

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.

Sample Code
@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;
Example

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.

Sample 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.
Developer-Relevant Activities
  1. Creating DDL Sources
  2. Defining a CDS table function

    See also: Editing DDL Source Code

  3. Adding Access Control to CDS Entities
  4. Checking Syntax of DDL Sources
  5. Activating DDL Sources
  6. Implementing a CDS table function in the AMDP class
  7. Debugging CDS Table Functions

    See also: Debugging AMDPs