In my recent project, I got a chance to work on BRF Plus and I found the benefits of BRF Plus very interesting. Generally when we talk about an application we always talk in terms on UI and backend logic. Interestingly if we look little closer, we can divide the backend logic as business processes and rules.
For instance creating a SO from lead is a business process and it remains the same for all entities, but what gets changed is the discount calculation for different buyers. The way the discounts are calculated becomes the part of business rules. Separating rules and processes helps in keeping the application stable. Here is where BRF plus helps us maintaining this segregation.
All the rules required by the application can be maintained in BRF Plus and it can be consumed in the application process where it is required.
Changes in the rules will not affect the application and hence keeping it more stable.
To open BRF Plus workbench use the transaction FDT_WORKBENCH in SAP CRM system. You can create your own application by clicking on ‘Create Application’.
While creating an application, it is important to maintain certain fields correctly based on your requirement:
- Access levels:
- Application: It can be accessed by other objects in the same application.
- Application Component: It can be accessed by other objects in the same application component.
- Superordinate Component: It can be accessed by all other objects under the same superordinate component. For example: an application is created under the component AP-ORD-REQ with superordinate component as the access level. This application can be accessed from any other component under AP-ORD.
- Top Component: It can be accessed by all other objects under the same top component. For example: an application is created under the component AP-ORD-REQ with top component as access level.
- Global: It can be accessed by all. It is public to be used by any application
- Storage Types: System Data, Customizing Data, Master Data
- In Properties tab, the exit class can be maintained.
- In Default tab, application log and language related setting can be done.
- All the objects in the application can be created from the ‘Contained Objects’ tab
- In Miscellaneous tab, DB connection details and rule set restart rules can be maintained.
- In general, a rules set execution is stopped if it meets an exit condition or after the last rule. But if the restart rule set flag is set, the rule set can be executed even after it has met an exit condition. This is called deferred mode.
- We can maintain DB connection details in database connection field. Expressions of type procedure call are executed from the mentioned DB.
To create a simple rule which can be exposed as a RFC function module or web service, select ‘Function’ in the ‘contained’ objects’ tab and create the object. The function can be defined in three modes –
1). Event Mode: The rule set are defined and executed to give the final output.
2). Functional mode: A top expression of any kind is executed and the final output is provided.
3). Event and Functional mode: After top expression is executed, the rule sets are also executed.
The function will contain importing and exporting parameters same as ABAP function. The importing parameter is called as context variable and exporting parameter is called as result set.
The context and result set can be defined with new data objects or existing data objects from DB can also be used.
The BRF Plus function can be generated as an ABAP classes. When the function is tested via simulation mode, it can be selected whether to run the function in generated mode or interpretation mode. In generation mode, the ABAP class will be executed. In interpretation mode, the rule set will be interpreted and then executed.
The rules in the function should be defined as rules set. Rule set are collection of rules. Rules can be defined with an expression type. Rules are always executed within a rule set, it cannot be executed independently. Predefined expression type is available and also customer can create their own expression types. Predefined expression types are available like
- Boolean Expression
- BRMS Connector Expression
- Case Expression
- Constant Expression
- DB Lookup Expression
- Decision Table Expression
- Decision Tree Expression
- Dynamic Expression
- Formula Expression
- Function Call Expression
- Loop Expression
- Procedure Call Expression
- Random Number Expression
- Search Tree Expression
- Table Operation Expression
- Value Range Expression
A simple rule can be like:
For a complex calculation, different features of BRF Plus like looping over table, appending values to a table and complex expression types can be used.
Different kinds of action are also possible which are executed based on the rules defined.
BRF Plus supports the following action types:
- Call Procedure Action
- Log Message Action
- Send Email Action
- Start Workflow Action
- Workflow Event Action
Advanced tools are available in the BRF Plus which is available only in expert mode. To change the user mode, select the personalize button in the right hand side and select expert as the mode. Various new options are shown in the Tools menu as an expert user. A BRF Plus function can be exposed as RFC FM or web service in the expert mode. The web service or RFC FM can be called from any application like java or SAP application. To call the BRF plus FM directly from ABAP code, the function ID is used. Function ID is visibility in ‘general’ block of the function in BRF Plus workbench. A context reference is defined and using that the function can be called.
PARAMETERS: p_salary TYPE SNWD_SALARY_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.
DATA: ls_tax TYPE if_fdt_types=>element_amount,
ls_salary TYPE if_fdt_types=>element_amount.
ls_salary–number = p_salary.
ls_salary–currency = ‘EUR’.
” Get BRFplus function
lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( ‘005056934CFD1EE3A7BF28BC1C865C25’ ).
” 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 ).
CATCH cx_fdt INTO lo_message.
Interesting feature of BRF Plus:
- It can be exposed as RFC function Module and Web Services which can be consumed from any SAP or Non-SAP system.
- Import and export for BRF rules is possible within different BRF Plus systems.
- Data types defined in backend system can be used
- Exit Classes can be added to the application. An application exit class must implement the IF_FDT_APPLICATION_SETTINGS interface
- Complete segregation of rules and processes for an application