1. 创建一个Core Data Service Table Functions

  • 新建 Core Data Service Table Functions
  • SAP 02-AMDP Functions for CDS Table Functions_AMDP


  • SAP 02-AMDP Functions for CDS Table Functions_Core_02


  • SAP 02-AMDP Functions for CDS Table Functions_Core_03

  • 定义CDS Table Functions
@EndUserText.label: 'a simple AMDP for CDS Table Functions'
@ClientDependent: true              //打开 Open SQL 的自动客户端处理

define table function ZAMDP_CDS_TABFUNC_01
with parameters @Environment.systemField: #CLIENT   //Open SQL 通过将sy-mandt的值隐式传递给该参数来处理
                ip_clnt:abap.clnt,       //入参client
                ip_COUNTRYFR:land1
                
returns {
            MANDT:abap.clnt;            //Field:ref elements
            CARRID:s_carr_id;
            CONNID:s_conn_id;
            COUNTRYFR:land1;
            CITYFROM:s_from_cit;
            AIRPFROM:s_fromairp;
            COUNTRYTO:land1;
            CITYTO:s_to_city;
            AIRPTO:s_toairp;
            FLTIME:s_fltime;
            DEPTIME:s_dep_time;
            ARRTIME:s_arr_time;
            DISTANCE:s_distance;
            DISTID:s_distid;
            FLTYPE:s_fltype;
            PERIOD:s_period;
}
implemented by method zamdp_demo_02=>GET_SPFLI_US;

SAP 02-AMDP Functions for CDS Table Functions_ci_04

2. 实现CDS Table Functions中的AMDP Class

  • 新建ABAP Class
  • 实现ABAP Class
CLASS zamdp_demo_02 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    interfaces: IF_AMDP_MARKER_HDB.

    class-methods:
        GET_SPFLI_US
            for table function zamdp_cds_tabfunc_01.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zamdp_demo_02 IMPLEMENTATION.
    method GET_SPFLI_US by database function
                        for hdb language sqlscript
                        options read-only
                        using spfli.
      return  select
                t1.MANDT,
                t1.CARRID,
                t1.CONNID,
                t1.COUNTRYFR,
                t1.CITYFROM,
                t1.AIRPFROM,
                t1.COUNTRYTO,
                t1.CITYTO,
                t1.AIRPTO,
                t1.FLTIME,
                t1.DEPTIME,
                t1.ARRTIME,
                t1.DISTANCE,
                t1.DISTID,
                t1.FLTYPE,
                t1.PERIOD
            from spfli as T1
            where t1.mandt = :ip_clnt      --Use Table Function Parameter
                and t1.COUNTRYFR = :ip_COUNTRYFR;
    endmethod.
ENDCLASS.

3. ABAP中调用AMDP Functions for CDS Table Functions

  • ABAP中调用CDS Table Functions
SELECT *
  FROM zamdp_cds_tabfunc_01( ip_countryfr = 'US' )
  INTO TABLE @DATA(result) ##db_feature_mode[amdp_table_function].

cl_demo_output=>display( result ).
  • 运行效果