先创建普通的视图

  @AbapCatalog.sqlViewName: ''
  @AbapCatalog.compiler.compareFilter: true
  @AbapCatalog.preserveKey: true
  @AccessControl.authorizationCheck: #CHECK
  @EndUserText.label: 'test table function'
  define view Ztab_Function as select from data_source_name {
    
  }

然后删掉代码,在下面选择templates
CDS Define Table Function With Parameters_字段
选择模板生成的代码

@EndUserText.label: 'test table function'
define table function Ztab_Function
with parameters parameter_name : parameter_type
returns {
  client_element_name : abap.clnt;
  element_name : element_type;
  
}
implemented by method class_name=>method_name;

加上自己需要的字段

@EndUserText.label: 'test table function'
define table function Ztab_Function
  with parameters
    cust_id : s_customer//传入的参数
returns
{
//要获取的字段
  client    : mandt;
  carrid    : s_carr_id;
  connid    : s_conn_id;
  fldate    : s_date;
  bookid    : s_book_id;
  custtype : s_custtype;

}
implemented by method zcl_tab_functions=>get_book_Id;//取数的sql

然后创建zcl_tab_function类,引用接口IF_amdp_marker_hdb.

CLASS zcl_tab_functions DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_amdp_marker_hdb .//接口
  class-METHODS get_book_id for table FUNCTION ztab_function.//添加方法
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_tab_functions IMPLEMENTATION.


  METHOD get_book_id BY DATABASE FUNCTION
        FOR HDB LANGUAGE SQLSCRIPT
        options READ-ONLY
        using sbook.
    RETURN SELECT mandt as client, carrid, connid,  fldate, bookid, custtype
            from sbook
            where mandt = session_context( 'CLIENT' )
            and customid = cust_id;
  ENDMETHOD.

ENDCLASS.

测试,右键选择提前输入参数值
CDS Define Table Function With Parameters_sql_02
结果:
CDS Define Table Function With Parameters_abap_03
到此结束。