Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions 

ABAP CDS - DEFINE TABLE FUNCTION

Other versions: 7.31 | 7.40 | 7.54

Syntax


[@entity_annot1] 
[@entity_annot2]
...
[@function_annot1]
[@function_annot2]
...
[DEFINE] TABLE FUNCTION cds_entity
         [parameter_list]
          element_list
          IMPLEMENTED BY METHOD amdp_function [;]

Effect

Defines a CDS entity cds_entity as a CDS table function in the CDS DDL. In platform-specific SQL, the CDS table function is implemented in an AMDP method amdp_function, which is created using the AMDP framework in the database system as an AMDP table function. The name cds_entity must comply with the naming conventions for dictionary types and can have a maximum of 30 characters.

  • parameter_list is used to declare a list of optional input parameters for the CDS table function. These also define the input parameters of the AMDP table function.
  • element_list is used to declare the elements of the CDS table function. These also define the columns of the tabular return value of the AMDP table function.
  • When amdp_function is used, an AMDP function implementation must be specified for an AMDP table function in the form amdp_class=>amdp_method. Here amdp_class is an AMDP class and amdp_method is an AMDP function implementation contained in this class. When this function implementation is declared, the current CDS table function is specified after the addition FOR TABLE FUNCTION. The AMDP function implementation must not exist when the CDS table function is created and activated. The name of an AMDP function implementation amdp_function can be specified in a single CDS table function only.

A CDS table function returns a tabular results set. Like any CDS entity, it can be used as a data source in other CDS entities or ABAP SQL read statements. The prerequisite for use is that the specified AMDP function implementation exists and is active.

A CDS table function is located in the namespace of the data types in ABAP Dictionary and in the namespace of the global object types in the class library.


Notes

  • Table functions constitute a database extension that is not supported by all database systems. However, the CDS DDL in ABAP CDS allows table functions to be created and accessed independently of the database system. If SELECT is used to access a table function or a view that contains table functions as data sources but the current database system does not support them, a non-handleable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised.

  • In an ABAP program, it is possible to use the method USE_FEATURES of the class CL_ABAP_DBFEATURES to check whether the current database system supports table functions. This requires the constant AMDP_TABLE_FUNCTION of the class to be passed to the method in an internal table.

  • The DDL source code of a CDS table function does not need to have the same name as the CDS table function, but it is advisable to use the name of the CDS table function.

  • After a piece of DDL source code is transported, the combination of its name and the name of the CDS table function view is defined and can no longer be modified by being renamed.

  • No classic ABAP Dictionary structure visible in the tools for classic structures is created for an CDS table function.

Example

The following DDL source code shows a client-specific CDS table function. It contains an input parameter (with the annotation @Environment.systemField and the predefined value #CLIENT) for the client, which is implicitly supplied with the ID of the current client when used as a data source of the ABAP SQL statement SELECT. For more information about how to use this function, see the executable example for AMDP Functions.

@ClientHandling.type: #CLIENT_DEPENDENT
define table function DEMO_CDS_GET_SCARR_SPFLI_INPCL
  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_DEMO_AMDP_FUNCTIONS_INPCL=>GET_SCARR_SPFLI_FOR_CDS;

Continue

ABAP CDS - DEFINE TABLE FUNCTION, function_annot

ABAP CDS - DEFINE TABLE FUNCTION, parameter_list

ABAP CDS - DEFINE TABLE FUNCTION, element_list