Calling a BRFplus function from an ABAP program

Business Rule Framework plus ( BRFplus ), also known as Formula and Derivation Tool ( FDT ), aims to  "Make 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 is Business Rules Engine allows 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 tutorial Building a Tax Calculation Application to 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
*
*---------------------------------------------------------------------*
*
*
*---------------------------------------------------------------------*

REPORT  z_brfplus_test.

PARAMETERS: p_salary TYPE amount.

DATA: lo_fuction    TYPE REF TO if_fdt_function,
      lo_context    TYPE REF TO if_fdt_context,
      lo_result     TYPE REF TO if_fdt_result.

DATA: lo_message    TYPE REF TO cx_fdt.
FIELD-SYMBOLS:
        TYPE if_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 function
      lo_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_SALARY' ia_value = ls_salary ).

      " Process the BRFplus function
      lo_fuction->process( EXPORTING io_context    =  lo_context
                           IMPORTING eo_result     =  lo_result ).

      " Retrieve the BRFplus function result
      lo_result->get_value( IMPORTING ea_value =  ls_tax ).

      WRITE ls_tax-number.
      WRITE ls_tax-currency.

    CATCH cx_fdt INTO lo_message.

      LOOP AT lo_message->mt_message ASSIGNING .
        WRITE: -text.
      ENDLOOP.

  ENDTRY.

The BRFplus function GUID can be retrieved by going to transaction BRFplus in the function's 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 program yields the same result.

Program input

Program result



3 comments:

  1. This Information which you provided is very much useful for us.. SAP Audit Services

    ReplyDelete
  2. This is very good news for market visitors. I suggest to every one for read this because there are lots of information which is help for promoting business.

    Free Nifty Future Tips

    ReplyDelete
  3. For SAP BRFplus training visit: https://sites.google.com/site/sapbrfplustraining/

    ReplyDelete