Practical use of BRF+ Application to design the Rules in SAP
What is BRF+ and the importance in S/4HANA?
BRF+ is an ABAP based framework and part of the NetWeaver stack. BRF+ stands for Business Rule Framework Plus and it provides a comprehensive application programming interface and user interface for defining business rules. It enables you to define business rules without the need of wiring ABAP code. The generated Business Rules can be incorporated into other SAP programs or Substitution/Validation rules.
BRF+ is not new and even not directly related to S/4HANA, but with the release of S/4HANA 1610, BRF+ gained more attention since it is launched as the go-to solution for some business processes. The most important ones are the changes in output management for Billing and Purchasing. I will come up with a separate blog post to provide step-by-step details for New Output management approach using BRF+ in S/4HANA.
There are many uses cases for BRF+, I will show a use case in Dunning Outputs on in this blog which I used recently and found very handy.Purpose of this article is to provide real time experiences and some good practices to be followed while working with BRF+ applications.
For displaying Salutation in Emails and Print Outputs, There are different rules defined.
Salutation determination logic depends on Business Partner attributes of the dunned BP.
Mainly, Salutation depends on :
- BP type ( person/Group/Organization )
- Academic Title ( Prof. , Dr. )
- Title ( Mr., Ms. )
- Language ( English, German )
Based on the requirements, First step I followed was to prepare a simple excel to segregate conditions, criteria , rules and results as follow:
When BP is Group/Organization
When BP is Person and Lang. is German
When BP is Person and Lang. is English
Based on above rules and requirements, I realized that most of the hard-coded texts can be configured separately in form of Decision tables where user can maintain the data and It would be used in the rule set. These Decision tables are type of Expression in BRF+ terminology.
1. Decision Table for maintaining the Fixed result texts based on BP type and Lang.
2. Decision Table for maintaining the Fixed component of salutation based on Title and Lang.
After designing the above decision tables with configuration data, I then realized that some of the data should be picked up from Customizing Data in SAP e.g. Text tables for Titles and Academic Titles since in backed , BP will have Title Key and Academic Title key and its required to fetch the respective texts. For that, I found another Expression type in BRF+ – Data Base Lookup.
1. DB Lookup for Title texts
DB Lookup in BRF+ are just like a SELECT query in ABAP where we need to provide DB table name and WHERE conditions.
2. DB Lookup for Academic Title texts
You can see that there is an option “View SQL” which will lead yo in another pop-up window to see the complete SQL query ( This feature is for our enthusiastic Developers )
So now, I have completed the design part of the BRF+ and will jump into system to implement it.
Transaction code to start the BRF+ application in SAP system is : BRF+ or BRFPLUS
Now I will show how BRF+ needs to be configured, tested and integrated in SAP. The steps in the BRF+ UI will consist of the follow steps:
- Application creation
- Data Object Creation
- Function Creation
- Decision Table Creation
- Rule set Creation
- Assigning rule set to function
- Simulation of the Business Rule
1. Create Application:
First step in BRF+ is to create the application.
It’s always recommended to fill the documentation as highlighted above so that Its clear the use of the Application and where exactly It has been called.
2. Create Function:
A function is the point of contact for any BRF+ application to be called from external applications. It requires a defined signature ( import parameters of a Function Module or methods in ABAP ) and a rule set ( we will see in later part of this article )
Next step is to create a function:
Functions can be created either from BRF+ Application-> Contained Objects-> Create Object by selecting type as “Function
OR We can directly right click on Application and create functions.
I followed the first option as It gives more understanding of the different components linked to each other.
Once created, A function can be visualized as follow:
1. Create a signature of the Function ( Importing parameters – single elements, Structure or Table
Result Data Object – single elements, Structure or Table
2. After that, Create a Rule Set which is actually a core for any BRF+ application. It can be referred in next sections later.
3. Once Application is ready, It can be tested in Simulation Mode by providing test data to Import parameters and verify the result.
3. Rule Set Creation:
As described above, Rule Set is a core of any BRF+ application . It contains set of rules which we want to be executed as soon as our BRF+ application Function is getting executed.It needs to be assigned at Function if created separately. Recommended would be to follow all these steps in the same order so system would take care automatically to assign and link various components.
Rules Set can be seen in a Function as :
Rule Set on It’s own can be shown as:
We can click on “Ruleset Header” and check the component of each ruleset.
With “Context Overview”, Option, We can collectively check all the allowed/linked Data objects with this Ruleset.
You can see all the data objects from signature of the Function, are also linked with this rule-set which means we can make use of these Data Objects to design various rules. Additionally, we can also see some more data objects . These are variables created in rule set header. These will be used internally by BRF+ application to hold the interim data. We can see the use of these in below rules :
We can declare an existing Data Objects or new Data objects as variables in a rule-set which should be available across the application. It’s like private attributes of a class which can be accessed across the class.
In my example, I created a rule to get this variable CONSTANT_TEXT from a decision table.
It will read the Decision table for Data Objects provided in the Function and return the matched result.
Exit Conditions in Rule Set:
For each rule in rule set, we can also provide exit conditions so that BRF+ will stop running the rest of the rules. ( In case you want rules should be applicable in sequential manner )
In above screenshot, I have added an exit condition after Rule 5. So Application will check if result data object is already filled, It wouldn’t run the remaining rules and will be exited.
In BRF+, There are different types Expressions like Decision table, DB Lookup, Procedure Calls, Formulas etc.
In the application in this article, I used Formula to derive the salutation based on different conditions/rules.
As per requirement, Salutation should be combination of some constant text, Academic title text( if provided ), Title text, First Name and Last name for different conditions.
Rule: When BP type = 1(Person), Language = DE(German), Academic Title is NOT initial, Title = 0001
Sehr geehrte(CONTANT_TEXT) Frau(TITLE_MEDI) Assoc. Prof.(ACADEMIC_TEXT)Bhatia(LAST_NAME)
For that, a formula is required which can read the context variables and concatenate them into desired sequence.
After set-up all the required rules in the rule-set, we can test our BRF+ application before integrating it to any external application. For that, Simulation feature is very handy where we can test our rules by providing some test data.
For that, Go to Function of the BRF+ application and select ‘Simulation” :
Once you get the screen to provide the import test data in parameters, You can also select an existing test variant:
Other options which SAP has provided to import the test data where a local file from drive can be uploaded which contains test data.I used variants which I created by passing test data by myself
Once variant is selected or test data is entered manually, We are ready to run the rules and get the result by selecting any of the below options:
1. When I selected “Execute”, I could see the result directly:
2. When I selected ” Execute and Display Processing Steps”, System would show me all the intermediate steps to get that result. It’s in general a debugging steps show case in BRF+ where one can get to know about each processing step.
Now, Our BRF+ Application is completely ready as tests on Simulation were working fine. So we can simply Integrate this into external applications and Here, ABAP developer job will be started ( Developers can also create BRF+ application but SAP has thought of this framework to be used and sometimes, created by users directly. You could see in all above steps that there is no special ABAP knowledge is needed ).
Integration into calling applications in ABAP:
A quick note to ABAPers : Before directly jumping into calling applications and start writing ABAP code, Please also check a cool feature that BRF+ has provided to help all the developers- Automated ABAP code generation which anyone can simply copy and paste into their calling programs.For that, Go to BRF+ Function again and check an option “Create Code Template” :
Therefore, There is no need to write the code from scratch. You can copy this template and paste in your application where you want to integrate BRF+ rules. As an ABAPer, You just need to provide data for the import parameters which I did as follow:
Testing Dunning Form:
After integrating the BRF+ application in Dunning Forms, I generated one test Dunning Run and checked the Dunning Output Form where the Salutation is being reflected as per the BRF+ Rules:
I hope this article would be useful for people who wants to use BRF+ in their project tasks. In case of any questions/Suggestions, Please contact me or share your feedback in comment section.