Technical Articles
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.
Business Requirements:
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 )
Design:
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
Rules for Group/Organization
When BP is Person and Lang. is German
Rules for BP as Person and language as German
When BP is Person and Lang. is English
Rules for BP as 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.
Decision Table for Fixed result
2. Decision Table for maintaining the Fixed component of salutation based on Title and Lang.
Decision Table for constant text in result
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
The following table is just a prototype how DB Lookup will consist the required SAP data.
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 )
SQL Query for DB lookup
So now, I have completed the design part of the BRF+ and will jump into system to implement it.
Implementation:
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.
Context Overview:
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 :
Variables:
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.
Decision Table:
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.
Formulas:
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
Expected result:
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.
4. Simulation:
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. “Execute”
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.
Hi Prabhjot,
Thanks for sharing blog on BRFplus with step by step.As you said in S/4,BRFplus playing key role in the output management and other areas as well.
Thanks,
Syam
Hi Prabhjot,
A very good blog describing how to create a new BRF application from scratch!
It could be also useful for readers to know the utility tcode FDT_HELPERS, which is a collection of various tools to monitor, explore, run performance analysis and where-used checks, create and maintain transport requires for BRF-related objects
Thanks!
Vlad
Hi Prabhjot,
Very helpful blog .
thank you
Shyam Kandapi
Thanks Prabhjot , now I got an Idea of BRF+ ... Thanks for the post which briefs well...
Thanks, Prabhjot. This blog is very useful.
@Prabhjot Bhatia
Thanks for sharing this, very clear now : P
Prabhjot,
Thanks for sharing this blog.. its is very useful to and key role is playing in S4 HANA .
Best Regards,
Prabhu. Pole
Hi @Prabhjot
Great document.
Would like to know as in my current project we user variant configuration can this be used to define rules for constrains to be created automatically.
Vignesh V
it's simply perfect. Easy to understand and every line is informative. Pleasure to read this blog.
Thanks for your feedback.. Really happy to know that its helpful
Is there any alternative to maintain the business rules or validation at database level. I want to use validate this rules at AMDP level. But BRF+ Rules are at not at database level.
Hi Prabhjot,
Thanks for sharing. Is there a document, tutorial on BRF+ & oData & Adobe Forms combination? I am trying to change Form of F110 output but could not find a way to trigger it to test new form.
Cheers
Hello Prabhjot,
Really great sharing. Now I have some ideas about how BRF+ works. Then I could dive in for the details.
Thanks.
Thanks Prabhjot,
This is the clearest guide to initial steps in BRF+ that I could find, unlike many other so-called guides which are simply screenshots of "how" and no mention of "why".
I've only just started looking at BRF+ and it seems to do exactly what I thought it would.
I don't know if it's the correct term but this is a kind of "code pushup", i.e. the decision is pushed out of the application logic and managed elsewhere. The inverse of code pushdown?
Case in point - I have to migrate some SAPScript logic with decades of legacy custom code and the decision tree in there looks like an inside-out pineapple in four dimensions. I'm hoping to implement some of the scarier parts as BRF+ "plugins" so that I am not constantly changing code in response to the usual "we never thought about that in the design phase" wailings.
There are some further considerations regarding developer involvement. While it is possible for a Citizen Developer or equivalent to design this rule it cannot be guaranteed as technically viable unless it is being used in custom applications or API's. In this case it is most likely that the developers can provide the context inputs since they control the code.
If the rule must be integrated via an enhancement, it would be prudent to determine if the context values can be provided at the enhancement point; this usually needs a code-savvy investigator to verify.
Other advantages of BRF+ that I see, but I cannot confirm if they are true yet.
Here goes then...