calling a brfplus function from an abap
DESCRIPTION
Calling a BRFplus Function From an ABAPTRANSCRIPT
Calling a BRFplus function from an ABAPprogram
Business Rule Framework plus ( BRFplus ), also known as Formula and Derivation Tool ( FDT ), aims toMake hard-coded rules in systems, process flows and services explicit and easy to change for business professionals. Replace complex table-based determination by an intuitive rule-based approach..
BRFplus isBusiness Rules Engineallows modelling and access rules. These rules consist of building blocks such as decision tables, decision trees and formulas, its purpose is to allow business professionals to change the rules quickly without the need of IT intervention ( ABAP programmer ). This way the system becomes nimbler with rules than can be changed faster.
we build on the SAP tutorialBuilding a Tax Calculation Applicationto show how we can implement the BRFplus function we already created from that tutorial.
Here is a sample code that could be used to consume our TAX_CALCULATOR BRFplus function.
*---------------------------------------------------------------------** Report Z_BRFPLUS_TEST**---------------------------------------------------------------------****---------------------------------------------------------------------*REPORTz_brfplus_test.
PARAMETERS: p_salaryTYPEamount.
DATA: lo_fuctionTYPE REF TOif_fdt_function,lo_contextTYPE REF TOif_fdt_context,lo_resultTYPE REF TOif_fdt_result.
DATA: lo_messageTYPE REF TOcx_fdt.FIELD-SYMBOLS:TYPEif_fdt_types=>s_message.DATA: ls_tax TYPE if_fdt_types=>element_amount,
ls_salary TYPE if_fdt_types=>element_amount.
START-OF-SELECTION.
CLEAR: ls_tax.ls_salary-number = p_salary.ls_salary-currency =EUR.
TRY. Get BRFplus functionlo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function(D4AE52BE7EF21ED284F8C146EFF7943E). Set the BRFplus function context ( input variables )lo_context = lo_fuction->get_process_context( ).lo_context->set_value( iv_name =GROSS_SALARYia_value = ls_salary ). Process the BRFplus functionlo_fuction->process(EXPORTINGio_context = lo_contextIMPORTINGeo_result = lo_result ).
Retrieve the BRFplus function resultlo_result->get_value(IMPORTINGea_value = ls_tax ).WRITEls_tax-number.WRITEls_tax-currency.
CATCHcx_fdtINTOlo_message.
LOOP ATlo_message->mt_messageASSIGNING.WRITE: -text.ENDLOOP.
ENDTRY.
The BRFplus function GUID can be retrieved by going to transaction BRFplus in the functions General TAB.
BRFplus function details
If we test our rule in the Business Rule Framework we get the following result.
Simulation framework
Context values ( BRFplus function input values )
BRFplus funtion similation steps and Result
Finally we can check that using our programyieldsthe same result.
Program input
Program result