Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184158
Active Contributor
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, flight 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, flight 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 figure.
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 figure 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, flight 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, flight 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 figure.
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 figure 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, flight 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 first thing we create the rule1. See above the rule  1.
Rule 1: if the age greater than or equal 18, flight 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, flight destination and the days stay ) to get the result.

We will add the flight 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 add 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( '50E549C2C40B1ED6A69FCB34B9365358' ).
" 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( '50E549C2C40B1ED6A69FCB34B9365358' ).
" 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
8 Comments
Labels in this area