先创建普通的视图
代码语言:javascript复制 @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
选择模板生成的代码
代码语言:javascript复制@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;
加上自己需要的字段
代码语言:javascript复制@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.
代码语言:javascript复制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.
测试,右键选择提前输入参数值
结果:
到此结束。