Professional Documents
Culture Documents
BRF Example PDF
BRF Example PDF
BRF Example PDF
Applies to:
CRM 5.0
Summary
This article explains the step by step approach of how BRF (Business Rules Framework) can be
used to map CRM business requirements without much of the ABAP code.
Author Bio
Kamal Shaik is a Consultant working for SAP GDC in the areas of ERP, CRM and XI.
© 2006 SAP AG 1
Table of Contents
BRF Introduction................................................................................................................. 3
Requirement................................................................................................................................. 3
Dependencies .............................................................................................................................. 3
Overview of steps......................................................................................................................... 3
© 2006 SAP AG 2
BRF Introduction
In simple terms, BRF is a runtime environment for evaluating and manipulating business data. This is
an event controlled framework which processes rule(s), where a rule is any logical expression
connected by an action definition.
Requirement
Let’s consider a simple scenario where we have customer specific field called “Risk Factor” at
service contract item level and need to calculate this Risk Factor based on some rules.
The business rule states that “Risk Factor (RF)” is calculated as below depending on sales
organization.
Dependencies
Overview of steps
• Create action profile and definition with a method call which gets triggered during the CRM
service contract. This method call will have the logic to trigger the BRF event.
• Copy all the standard BRF objects (events, expressions etc) to this application class
• Create BRF expressions for each of the elements in the Risk Factor calculation
• Create and register BRF action and assign a custom function module which gets executed to
update the contract with RF value
• Create and register BRF event and assign the BRF action
© 2006 SAP AG 3
Step 1: Action Profile
Create action profile and definition in the SPRO and assign to service contract transaction (SC).
© 2006 SAP AG 4
© 2006 SAP AG 5
The code for this method call is given at the end.
Before proceeding with the actual steps of BRF, we need to create a unique application class and
make all the BRF objects (events, rules, expressions etc) available to this application class. These
steps are available in the sap help in detail
Step 2.1
© 2006 SAP AG 6
Execute transaction BRFIMC01. Select RULES for Implementing class field. Enter the
application class with import status to ‘A’ and execute. Repeat the same process for
implementing class EVENT.
Execute BRF and select the application class you have created.
Expand All Groups folder. From the context menu, create an expression as shown below.
This expression will be of constant (0CN001) type with a fixed value of 0.05. This constant value is
then used in the calculation of Risk Factor.
© 2006 SAP AG 7
Similarly create another expression of type constant with fixed value of 0.07.
SAP provides standard reporting structures/tables to access/store CRM order data. Before we use
one of these standard structures, they have to be registered in BRF. Execute BRF and choose
Utilities → Data Sources and register structure CRMT_REPORT_PRICING_ITEM as shown below
along with the new function module which will be used to access this structure.
© 2006 SAP AG 8
Now, create an expression of type 0SM001 (value request) to get the net value of line item in a
contract.
© 2006 SAP AG 9
Once you select the structure and field name, the other fields are automatically populated.
Similarly, create an expression (value request) to get the sales organization as shown below. The
structure used will be CRMT_REPORT_ORGMAN and this again has to be registered as the data
source in BRF.
1
© 2006 SAP AG
0
The FM used here to access sales organization will have to be created and the code will be similar
as shown in the above step. Note that, separate function modules will be required in case; the
required data for the calculation is not available in the same structures/tables.
Create an expression of type formula as shown below. This formula is the one which calculates the
“Risk Factor”.
1
© 2006 SAP AG
1
Go to the formula editor and define the formula as shown below.
Using the formula editor, you can design any type of logical expression.
1
© 2006 SAP AG
2
Select implementing class as function module execution.
Double click 0FM001 and assign function module to be executed. This function module is the one
that updates the contract with the RF value.
1
© 2006 SAP AG
3
Step 7: BRF Event
Create BRF event and assign the action and expression as shown below
The source code for BADI ZT_RISK_FACTOR is exactly the same as in the standard function
module BRF_DEMO_RAISE_EVENT_SAMPLE. The input vales are
IV_EVENT = ‘ZEVENT’
IV_APPLCLASS = ‘ZSKHAPPCLASS’
1
© 2006 SAP AG
4
*Get the GUID of the order to update
IMPORTING
EV_1O_MAIN = LCL_ONE_ORDER.
LV_CURRENT_GUID = LCL_ONE_ORDER->GV_UI_STATUS->GET_CURRENT_GUID( ).
ENDIF.
*IT_EXPRESSIONS will have all the expressions and the corresponding resulting values.
IF LS_EXPRESSION-EXPRESSION = 'ZT_RF_FORMULA'.
LV_RF_VALUE = LS_EXPRESSION-RESULT_VALUE.
ENDIF.
ENDLOOP.
EXPORTING
IT_HEADER_GUID = GUID_TAB
IMPORTING
ET_CUSTOMER_I = ET_CUSTOMER_I.
CRMT_CUSTOMER_I_WRK-ZZRISK_FACTOR = LV_RF_VALUE.
EXPORTING
IS_CUSTOMER_I_WRK = CRMT_CUSTOMER_I_WRK.
1
© 2006 SAP AG
5
Step 10: Conclusion
To trigger BRF events during the CRM transactions, standard template function modules are
available, and thus the amount of custom logic is largely minimized. Search for BRF* in SE37 for
these templates.
The above example was developed in CRM 5.0 and there will be differences when using other
versions. For example, the BRF user interface, the standard template function modules and BRF
classes are different. But the overall approach is same in all versions.
SAP will not be held liable for any damages caused by using or misusing the information, code or
methods suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the
content of this technical article or code sample, including any liability resulting from incompatibility
between the content within this document and the materials and services offered by SAP. You agree
that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.
1
© 2006 SAP AG
6