Вы находитесь на странице: 1из 21

Products

Products Industries
Industries Services and Support
Services Support Training
Training Community
Community Developer
Developer

Partner
Partner About
About

 
Ask a Question Write a Blog Post Login

Ebrahim Hatem
November 10, 2016 8 minute read

Example to use Business Rule Framework plus


Follow RSS feed Like

4 Likes 18,308 Views 6 Comments

I just want to explain about this rule with an example. Every one has won rule or plan, or game. Anything wich a
condition we can call it as rule. There are many rules in our life, which could be divided into 3 parts as I know,
simple, medium or complex.
SAP provides business rules framework to manage the business rules. BRF consists of UI, rules repository and a
rules engine.
To express a rule we can use Decision Tables or Decision Trees. In this example, I will try to explain the decision
Table and how to do it in SAP by using sap transaction “BRF+” or “BRFPLUS”.
I would like to put simple rules for travel agency to buy ticket with some rules depends on three conditions age,
ight destination and the how many day will be the passenger stay.

This is called “Decision Table”


we can see in this table that there are 3 rules
Rule 1: if the age greater than or equal 18, ight destination is madrid and the days to stay there more than 5
days, then the passanger will get discount 20%.
Rule 2: if the age of the passanger between 2 and 17 ( greater or equal 2 and less than 18 ) the passanger will get
discount 30% where the distination and days stay will not be taken into consideration.
Rule 3: if the passanger age less than 2, then the passanger will get a discount 100%. He can get ticket free.
So how can we represent thes rules in SAP by using BRF+?
These Rules could be applied in ABAP or any programming langauge by using if statmemnts or switch case and
you can do what you want. But to avoid programming we can use SAP customizing tables and ABAP code to
make it easy and understandable for Business Analyzer and the programmer.
Creating Rules in BRFplus.
To create rules in PRFplus, there are three important steps to do it
1- Create an application
2. Create BRFplus function and the rules
3. Call the BRFplus function in ABAP.
1. Creating a BRFplus Application
We can start to create a BRFplus application by usnig the transaction “BRF+” or “BRFplus”, then you will be
asked to enter username and password.
Then you can just create the application as shown in this gure.
Enter the application name and short text about it.
Development package you can use TMP if you don’t want to transport it, otherwise you will asked to choose the
transport number. In our example we don’t need to transport these rules to another system, just as local as an
example.

2. Create BRFplus function and the rules

In this gure we can create a BRFplus function by clicking on the


“contained object” and then choose the type ” Function” and createb object.

I just want to explain about this rule with an example. Every one has won rule or plan, or game. Anything wich a
condition we can call it as rule. There are many rules in our life, which could be divided into 3 parts as I know,
simple, medium or complex.

SAP provides business rules framework to manage the business rules. BRF consists of UI, rules repository and a
rules engine.

To express a rule we can use Decision Tables or Decision Trees. In this example, I will try to explain the decision
Table and how to do it in SAP by using sap transaction “BRF+” or “BRFPLUS”.
I would like to put simple rules for travel agency to buy ticket with some rules depends on three conditions age,
ight destination and the how many day will be the passenger stay.

This is called “Decision Table”


we can see in this table that there are 3 rules

Rule 1: if the age greater than or equal 18, ight destination is madrid and the days to stay there more than 5
days, then the passanger will get discount 20%.

Rule 2: if the age of the passanger between 2 and 17 ( greater or equal 2 and less than 18 ) the passanger will get
discount 30% where the distination and days stay will not be taken into consideration.

Rule 3: if the passanger age less than 2, then the passanger will get a discount 100%. He can get ticket free.

So how can we represent thes rules in SAP by using BRF+?

These Rules could be applied in ABAP or any programming langauge by using if statmemnts or switch case and
you can do what you want. But to avoid programming we can use SAP customizing tables and ABAP code to
make it easy and understandable for Business Analyzer and the programmer.

Creating Rules in BRFplus.

To create rules in PRFplus, there are three important steps to do it


1- Create an application
2. Create BRFplus function and the rules
3. Call the BRFplus function in ABAP.

1. Creating a BRFplus Application


We can start to create a BRFplus application by usnig the transaction “BRF+” or “BRFplus”, then you will be
asked to enter username and password.

Then you can just create the application as shown in this gure.
Enter the application name and short text about it.
Development package you can use TMP if you don’t want to transport it, otherwise you will asked to choose the
transport number. In our example we don’t need to transport these rules to another system, just as local as an
example.
2. Create BRFplus function and the rules

In this gure we can create a BRFplus function by clicking on the


“contained object” and then choose the type ” Function” and createb object.
In this step, we can create our elements like age, ight destination and days stay as well as to the result
discount. In this example we have many elements, so we can choose add multiple elements.

These elements could be text or number, so we can choose the element type.
Our result consists of one element which is discount, it could as structure or table.
So we can create the discount as result of the our rules.
After that we can create our rules and try to save the changes.
We can now switch to the tab “Assigned Rulesets” to create the  rules.
 

To create a rules, just under the insert rules, click on the create  …..>
So the rst thing we create the rule1. See above the rule  1.
Rule 1: if the age greater than or equal 18, ight destination is madrid and the days to stay there more than 5
days, then the passanger will get discount 20%.

We have in this rule 1, three variables ( age, ight destination and the days stay ) to get the result.

We will add the ight destination,

We have many variables, so we have to add more condition, like this example

if A = … and B = … then …

else.
In this rule we can set the destination”  Madrid”
And days stay greater than 5 days,

Our rules depend on the age. So we can ass the age as precondition.
So we have to assign the age as precondition.

In this rule 1, the age must be equal or greater than 18.

We can repeat the same steps to create rule 2.


Rule 2: if the age of the passenger between 2 and 17 ( greater or equal 2 and less than 18 ) the passenger will get
discount 30% where the destination and days stay will not be taken into  consideration.

Rule 3: if the passenger age less than 2, then the passenger will get a discount 100%. He can get ticket free.

After creating all the rules, don’t forget to save and active them.

Now our rules have been created and they are ready to use them in ABAP.

3. Call the BRFplus function in ABAP.

To use these rules in ABAP, we have to use the this three operations.

 
” Get BRFplus function
lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )

>get_function( ’50E549C2C40B1ED6A69FCB34B9365358ʹ ).

The function number , you can get it from general data

" Get BRFplus function


lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( '50E549C2C40B1ED6A6
" Set the BRFplus function context ( input variables )
lo_context = lo_fuction->get_process_context( ).
lo_context->set_value( : iv_name = 'AGE' ia_value = p_age ),
iv_name = 'FLIGHT_DES' ia_value = p_fl_des ),
iv_name = 'STAY' ia_value = p_stay ) .

" 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 = lv_discount ).
 

Try this simple program but don’t forget to change the function ID.

REPORT zibo_pg_decision_table1.
" the parameters
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t001..
PARAMETERS:
p_age TYPE age DEFAULT '20',
p_fl_des TYPE zibo_de_flugziel DEFAULT 'Madrid',
p_stay TYPE zibo_de_aufenthalt DEFAULT '6'.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(13) text-001 .

*SELECTION-SCREEN COMMENT 33(3) lv_resul.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

" Data definitions


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: lv_discount TYPE c LENGTH 3.

FIELD-SYMBOLS: <ls_message> TYPE if_fdt_types=>s_message.

INITIALIZATION.
t001 = 'Selection Criteria'.

START-OF-SELECTION.
PERFORM execute_rules.
PERFORM print_descision.
FORM execute_rules.
TRY .
" Get BRFplus function
lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( '50E549C2C40B1ED6A6
" Set the BRFplus function context ( input variables )
lo_context = lo_fuction->get_process_context( ).
lo_context->set_value( : iv_name = 'AGE' ia_value = p_age ),
iv_name = 'FLIGHT_DES' ia_value = p_fl_des ),
iv_name = 'STAY' ia_value = p_stay ) .

" 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 = lv_discount ).

CATCH cx_fdt INTO lo_message.


LOOP AT lo_message->mt_message ASSIGNING <ls_message>.
MESSAGE <ls_message>-text TYPE 'I'.
ENDLOOP.
ENDTRY.

ENDFORM.

FORM print_descision.
write:'Age :', (20) p_age.
write:/'Flight desstination :',(80) p_fl_des.
write:/'Days of stay :', (80)p_stay.
ULINE.

Write:'The Discount is :' ,lv_discount ,'%'.

ENDFORM.

You can try all the possibilities and you will get the result ( Discount % ) as has done in decision table.
Regards

Ebrahim

Alert Moderator

Assigned tags

NW ABAP Business Rule Framework (BRFplus) |

Related Blog Posts

Business Rules United – 2018 Updates


By Ramana Mohanbabu , Oct 09, 2018

Where will I nd Business Rule related Stu (UPDATE)?


By Christian Lechner , Oct 03, 2016

Interface Data Validation – Power of BRF+


By Kunaal Masih , Feb 07, 2017
Related Questions

S4 HANA 1610; No output is getting generated BRF Plus


By Former Member , Feb 06, 2017

SLA implementation in SAP Solution Manager 7.1 using the BRFPLUS framework
By Former Member , Jun 06, 2017

Using BRF plus


By Natalia Timoshenko , Jan 09, 2019

6 Comments

You must be Logged on to comment or reply to a post.

Muhammad Zafarullah

November 11, 2016 at 5:34 pm


Usefull Information

Like (1)

Christian Lechner

November 14, 2016 at 2:41 pm


Hi Ebrahim,

thanks for sharing this information. Nevertheless, there are some points that have to be mentioned:

(1) It is best practice to leave the short text of BRFplus objects empty. Just use the Text eld as these allows a
more readable naming of your objects. You should also customize your UI accordingly that only the Long Texts
for your objects are shown.
(2) Your way of calling a BRFplus function is outdated and shall not be used anymore, as it can lead to
performance issues. The optimal way of how to call a BRFplus function is described
here;: https://blogs.sap.com/2015/10/18/brfplus-basics-how-to-call-a-function/
(3) Quite general, but please check the spelling and the typos in your blog, as it is currently quite hard to read
at several spots :-(.

Best regards,
Christian
Like (3)

Ebrahim Hatem | Post author

November 26, 2016 at 4:15 pm


Hallo Christian,
thank you very much for this feedback I will try to do the points what you have mentioned next time.
Best Regards
Ebrahim

Like (1)

Former Member

September 6, 2017 at 12:51 pm


Hi Ebrahim,

thanks for the post, good example to get used to BRF+.

However, there is one point I do not get. You are talking about Decision Tables all the time, but when setting up
the rules you are not using the Expression Type “Decision Table” at all.

I think the rules 1, 2 and 3 described above can be replaced with one single decision table using AGE, DEST and
STAY as input columns and  DISCOUNT as result column.

Best regards

Hannes

Like (1)

Ebrahim Hatem | Post author

October 12, 2017 at 10:46 am


Hi Hannes,

Thank you for your comment. I think when there are complex rules, these rules should be managed and at the
end one decision should be taken. Maybe I am wrong!

According to your point 2.  you are absolutely right

 
Best regards

Ebrahim

Like (0)

Former Member

February 21, 2018 at 3:32 pm


Has anybody thought of applying BRF principles in Product Con guration area?

Like (0)

Share & Follow

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Sitemap Newsletter

Вам также может понравиться