You can utilize CDS table functions for your task and their capability to store intermediate results in internal table. It is yet available since 7.40 SP05 when AMDP was released, and table functions are available since 7.50.
Supposing you has CDS view with orders which is implemented by table function 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;
You want to fetch vendor ID for each order through BRF+ by order ID.
To fulfill the task in you table function implementing class you should create separate method that will call BRF+ and update intermediate itab and in the main table function method re-read your internal table into final CDS view.
Possible implementation of AMDP class:
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.
Note that in CDS-implementing method (if_amdp_marker_hdb
interface) you can use only SQLScript statements, but in other methods you can use ABAP.