其他分享
首页 > 其他分享> > 使用ABAP调用BRF+ function

使用ABAP调用BRF+ function

作者:互联网

针对如下的BRF+ function:

clipboard1

基于如下输入,根据rule的规则,计算出的final price应等于 10 / ( 1 + 0.12 ) = 8.93
clipboard2

可以使用如下的report来将上述输入传入brf+的API,通过ABAP 代码来调用function的执行:

REPORT zcall_function.
 
DATA: lo_function TYPE REF TO if_fdt_function,
      lo_context  TYPE REF TO if_fdt_context,
      lo_result   TYPE REF TO if_fdt_result,
      lx_fdt      TYPE REF TO cx_fdt,
      lv_string   TYPE string.
FIELD-SYMBOLS <ls_message> TYPE if_fdt_types=>s_message.
lo_function =
cl_fdt_factory=>if_fdt_factory~get_instance(
)->get_function( iv_id = 'FA163E8EAB031EE48B847ADC6A96D5F0' ).
TRY.
    lo_context = lo_function->get_process_context( ).
    lo_context->set_value( iv_name = 'CUSTOMER'
    ia_value = 'sap' ).
    lo_context->set_value( iv_name = 'ITEM' ia_value = 'pencil' ).
    lo_context->set_value( iv_name = 'PROMOTION' ia_value = space ).
    lo_context->set_value( iv_name = 'SHELF_PRICE'
    ia_value = '10' ).
    lo_function->process( EXPORTING io_context = lo_context
    IMPORTING eo_result = lo_result ).
    lo_result->get_value( IMPORTING ea_value = lv_string ).
    WRITE lv_string .
  CATCH cx_fdt INTO lx_fdt.
    LOOP AT lx_fdt->mt_message ASSIGNING <ls_message>.
      WRITE / <ls_message>-text.
    ENDLOOP.
ENDTRY.

report输出和在BRF+ workbench里得到的结果一致:
clipboard3

标签:function,lo,value,ABAP,fdt,context,BRF,TYPE
来源: https://blog.csdn.net/i042416/article/details/95735697