Core Data Services (CDS) ABAP

CDS Table Functions

Motivation: Why Table Functions?

CDS views are often sufficient — but sometimes you need more powerful features:

  • When complex logic is required
  • When HANA-specific SQL functions or SQLScript are needed
  • When dynamic data access is necessary
  • When data must be read from another DB schema

➡️ CDS Table Functions are AMDP functions implemented in SQLScript but consumed just like a CDS object.

What Is a CDS Table Function?

What Is a CDS Table Function?

  • Combination of a CDS definition & SQLScript logic
  • Not a classical view — instead:
    • CDS DDL source definition
    • ABAP method in an AMDP class
  • Returns a tabular result set, just like a CDS view

D Defining a CDS Table Function

The CDS Data Definition defines the structure of the table function:

  • Parameters (optional)
  • The field list of the return table

At the end, the implementation method is referenced using:

IMPLEMENTED BY METHOD <ClassName>=><MethodName>

@EndUserText.label: 'Table Function'

define table function zi_table_function

returns
{
  mandt : abap.clnt;
  Country : land1;
  CountryText: landx50;
}

implemented by method zcl_amdp_table_function=>CountryText;

C Implementation in AMDP

Implementation is done as an ABAP Managed Database Procedure (AMDP) inside an ABAP class.

Requirements:

  • The interface IF_AMDP_MARKER_HDB must be implemented
  • The method must be static (CLASS-METHODS)
  • Instead of a parameter definition, it uses:
    FOR TABLE FUNCTION <tf-name>
CLASS zcl_amdp_table_function DEFINITION 
  PUBLIC FINAL CREATE PUBLIC.

  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    CLASS-METHODS CountryText FOR TABLE FUNCTION zi_table_function.

ENDCLASS.

CLASS zcl_amdp_table_function IMPLEMENTATION.
  METHOD countrytext
        BY DATABASE FUNCTION
        FOR HDB LANGUAGE SQLSCRIPT
        OPTIONS READ-ONLY
        USING t005t.

    TMP = select distinct mandt,
                          land1 as Country,
                          landx as CountryText
                   from t005t
                   where mandt = session_context( 'CLIENT' );

    return select mandt,
                  Country,
                  string_agg( CountryText, '/' ) as CountryText
                  from :TMP
                  group by Country, mandt;
  ENDMETHOD.
ENDCLASS.

Usage in ABAP

SELECT * FROM ztf_kunden_umsatz( p_kunnr = '123456' )
  INTO TABLE @DATA(result).

➡️ Directly usable in Open SQL
➡️ Also consumable inside CDS views

Typical Use Cases

✅ Complex calculations
✅ Multiple dependent processing steps
✅ Use of HANA-specific features not available in CDS (e.g., window functions)
✅ Access to other schemas, e.g. _SYS_BIC

Best Practices

✔️ Use only when justified
✔️ Avoid imperative logic
✔️ Write clean SQLScript!

Summary

  • Table functions = CDS definitions with SQLScript logic behind them
  • Enable HANA-specific features and complex calculations
  • Not a replacement for CDS views — but a powerful extension
  • Always consider performance and readability