Skip to content

Instantly share code, notes, and snippets.

@js1972
Created August 18, 2014 02:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save js1972/9e2de7819275269cfbc1 to your computer and use it in GitHub Desktop.
Save js1972/9e2de7819275269cfbc1 to your computer and use it in GitHub Desktop.
ABAP program to execute a BRF+ Function. In production code SAP recommends using program fdt_template_function_process to generate the required ABAP code. This gist is for testing...
report y_brfplus_function_test.
data: lo_admin_data type ref to if_fdt_admin_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,
result type abap_bool,
event_code type string.
parameter: p_evt type string.
event_code = p_evt.
start-of-selection.
"GENERATED (OPTIMISED) CODE FROM PROGRAM fdt_template_function_process
"See: https://scn.sap.com/thread/2014761
constants:lv_function_id type if_fdt_types=>id value '0050568201851EE4898822F30A7D3244'.
data: lv_timestamp type timestamp,
lt_name_value type abap_parmbind_tab,
ls_name_value type abap_parmbind,
lr_data type ref to data,
lx_fdt type ref to cx_fdt,
la_z_mm_le_delivery_evt_code type if_fdt_types=>element_text.
field-symbols <la_any> type any.
get time stamp field lv_timestamp.
ls_name_value-name = 'Z_MM_LE_DELIVERY_EVT_CODE'.
la_z_mm_le_delivery_evt_code = event_code.
get reference of la_z_mm_le_delivery_evt_code into lr_data.
ls_name_value-value = lr_data.
insert ls_name_value into table lt_name_value.
cl_fdt_function_process=>get_data_object_reference( exporting iv_function_id = lv_function_id
iv_data_object = '_V_RESULT'
iv_timestamp = lv_timestamp
iv_trace_generation = abap_false
importing er_data = lr_data ).
assign lr_data->* to <la_any>.
try.
cl_fdt_function_process=>process( exporting iv_function_id = lv_function_id
iv_timestamp = lv_timestamp
importing ea_result = <la_any>
changing ct_name_value = lt_name_value ).
catch cx_fdt into lx_fdt.
endtry.
write: / 'Result for event code ', event_code, 'is: ', <la_any>.
exit.
" my old code - simpler - but SAP say the above is more optimised (somehow)?!?
cl_fdt_factory=>get_instance_generic( exporting iv_id = '0050568201851EE4898822F30A7D3244' importing eo_instance = lo_admin_data ).
lo_function ?= lo_admin_data.
lo_context ?= lo_function->get_process_context( ).
lo_context->set_value( iv_name = 'Z_MM_LE_DELIVERY_EVT_CODE' ia_value = event_code ).
try.
lo_function->process( exporting io_context = lo_context importing eo_result = lo_result ).
lo_result->get_value( importing ea_value = result ).
write: / 'Result for event code ', event_code, 'is: ', result.
catch cx_fdt into lx_fdt.
endtry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment