您可以将 CDS 表函数用于您的任务以及它们将中间结果存储在内部表中的能力。自 AMDP 发布时的 7.40 SP05 以来它仍然可用,并且自 7.50 以来表函数可用。
假设您有带有订单的 CDS 视图,由表函数实现zcl_cds_ord
@EndUserText.label: 'BRF function'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define table function ZCDS_ORD_FUNC
returns {
mandt :mandt;
ebeln :ebeln;
bstyp :ebstyp;
vendor_id :lifnr;
}
implemented by method zcl_cds_ord=>get_vendor;
您想通过 BRF+ 按订单 ID 获取每个订单的供应商 ID。
要完成表函数实现类中的任务,您应该创建单独的方法,该方法将调用 BRF+ 并更新中间 itab,并在主表函数方法中将内部表重新读取到最终 CDS 视图中。
AMDP 类的可能实现:
CLASS zcl_cds_ord DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
TYPES: BEGIN OF ty_orders,
mandt TYPE mandt,
ebeln TYPE ebeln,
bstyp TYPE ebstyp,
vendor_id TYPE lifnr,
END OF ty_orders,
tty_orders TYPE STANDARD TABLE OF ty_orders.
INTERFACES if_amdp_marker_hdb.
CLASS-METHODS get_vendor FOR TABLE FUNCTION zcds_ord_func.
METHODS call_brf CHANGING it_orders TYPE tty_orders.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_cds_ord IMPLEMENTATION.
METHOD get_vendor BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
itab_orders = SELECT mandt,
ebeln,
bstyp,
'' AS vendor_id
FROM ekko;
CALL call_brf CHANGING itab_orders.
RETURN SELECT mandt, ebeln, bstyp, vendor_id
FROM :itab_orders.
ENDMETHOD.
METHOD call_brf.
DATA: lo_fuction TYPE REF TO if_fdt_function.
* Get BRFplus function
lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( '50E549C2C40B1ED6A69FCB34B9365358' ).
* Set the BRFplus function context ( input variables )
DATA(lo_context) = lo_fuction->get_process_context( ).
LOOP AT it_orders ASSIGNING FIELD-SYMBOL(<fs_order>).
lo_context->set_value( : iv_name = 'ORDER_ID' ia_value = <fs_order>-ebeln ) .
* Process the BRFplus function
lo_fuction->process( EXPORTING io_context = lo_context
IMPORTING eo_result = DATA(lo_result) ).
* Retrieve the BRFplus function result
lo_result->get_value( IMPORTING ea_value = <fs_order>-vendor_id ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
请注意,在 CDS 实现方法(if_amdp_marker_hdb
接口)中,您只能使用SQLScript语句,但在其他方法中,您可以使用 ABAP。