Sie sind auf Seite 1von 16

SDN Cont ri but i on

BRF (Business Rules Framework) Tool in CRM


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.
Created on: 17 May 2006
Author Bio
Kamal Shaik is a Consultant working for SAP GDC in the areas of ERP, CRM and XI.


2006 SAP AG 1






2006 SAP AG 2





Table of Contents
BRF Introduction................................................................................................................. 3
Requirement................................................................................................................................. 3
Dependencies .............................................................................................................................. 3
Overview of steps......................................................................................................................... 3
Step 1: Action Profile................................................................................................................ 4
Step 2: BRF Application Class ................................................................................................. 6
Step 3: BRF Expressions ......................................................................................................... 7
Step 4: BRF Expressions with Data Source............................................................................. 8
Step 5: BRF Formula Expression........................................................................................... 11
Step 6: BRF Action................................................................................................................. 12
Step 7: BRF Event.................................................................................................................. 14
Step 8: BADI source code...................................................................................................... 14
Step 9: Update Contract with the BRF results ....................................................................... 14
Step 10: Conclusion............................................................................................................... 16
Disclaimer and Liability Notice.......................................................................................... 16











2006 SAP AG 3





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
Lets 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.
If Sales Org is 50000155, RF =0.05 * Net value of product
Else RF =0.07 * Net value of product
Dependencies
CRM One Order concept
Understanding of action profile management in CRM
ABAP Object Oriented skills
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.
Define BRF application class
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
Expression/s representing constant values 0.05 and 0.07
Expression representing Net value of product
Expression representing sales organization
Expression representing RF formula
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
Develop logic in the required function modules to access/update contract data

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.
Step 2: BRF Application Class
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
Execute transaction BRFAPL01 and define a new application class.
Execute transaction BRF and create the application class.
Execute program BRF_COPY_IMPL_CLASSES. In the Implementing Class field, enter an
asterisk (* means all objects) for the above application class. This will copy all the standard
implementing classes to the new application class. Note that each BRF object is represented
by a class. For example, BRF Event is represented by CL_EVENT_BRF.

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.
Step 3: BRF Expressions
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.
Step 4: BRF Expressions with Data Source
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.

Create the above function module by using function module BRF_DATA_GET_TEMPLATE as a
copy template. The required input parameter is structure name (field and event name not required
here). The output parameter is the order data (in this example, net value of product). The source
code is given below.

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.

2006 SAP AG
1
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.

Step 5: BRF Formula Expression
Create an expression of type formula as shown below. This formula is the one which calculates the
Risk Factor.


2006 SAP AG
1
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.
Click to get the technical names of the formula.

This formula matches the requirement.

Step 6: BRF Action
Create a BRF action as shown below.


2006 SAP AG
1
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.



2006 SAP AG
1
3






Step 7: BRF Event
Create BRF event and assign the action and expression as shown below


Step 8: BADI source code
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

Step 9: Update Contract with the BRF results
The code for the FM ZT_RF_RETURN is given below.



2006 SAP AG
1
4






2006 SAP AG
1
5





*Get the GUID of the order to update
CALL FUNCTION 'CRM_1O_INSTANCE_GET_UI'
IMPORTING
EV_1O_MAIN = LCL_ONE_ORDER.
IF NOT LCL_ONE_ORDER IS INITIAL.
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.
*Loop all expressions and get the Risk Factor value
LOOP AT IT_EXPRESSIONS INTO LS_EXPRESSION.
IF LS_EXPRESSION-EXPRESSION = 'ZT_RF_FORMULA'.
LV_RF_VALUE = LS_EXPRESSION-RESULT_VALUE.
ENDIF.
ENDLOOP.
*Update the RF value in the contract
MOVE LV_CURRENT_GUID TO GUID_TAB_WA.
APPEND GUID_TAB_WA TO GUID_TAB.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
IT_HEADER_GUID = GUID_TAB
IMPORTING
ET_CUSTOMER_I = ET_CUSTOMER_I.
READ TABLE ET_CUSTOMER_I INTO CRMT_CUSTOMER_I_WRK INDEX 1.
CRMT_CUSTOMER_I_WRK-ZZRISK_FACTOR = LV_RF_VALUE.
CALL FUNCTION 'CRM_CUSTOMER_I_PUT_OB'
EXPORTING
IS_CUSTOMER_I_WRK = CRMT_CUSTOMER_I_WRK.


2006 SAP AG
1
6






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.
Disclaimer and Liability Notice
This document may discuss sample coding or other information that does not include SAP official
interfaces and therefore is not supported by SAP. Changes made based on this information are not
supported and can be overwritten during an upgrade.
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.

Das könnte Ihnen auch gefallen