Nothing Special   »   [go: up one dir, main page]

Business Rule Framework Plus (Brfplus) : DDC Quick Reference Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

Business Rule Framework

plus (BRFplus)
DDC QUICK REFERENCE GUIDE
CHUAK
Version 1.0 FEN SOO
LAST UPDATED: 29.11.17
DOCUMENT INFORMATION

The contents of this document remain strictly confidential to Rizing – Digital Development Center and
its affiliated companies. All rights to any ideas, inventions, copyright works, designs or any other types
of intellectual property in the contents belong to Rizing.

DOCUMENT REVISION HISTORY


Date Version Description Author

29/11/17 0.1 Draft Version Soo Chuak Fen

DOCUMENT REVIEWERS
Name Organisation Position

Ruslim Chang Digital Development Center - Rizing Technical Manager

www.rizing.com
TABLE OF CONTENTS

DOCUMENT INFORMATION ................................................................................................................ i


TABLE OF CONTENTS ......................................................................................................................... ii
INTRODUCTION ................................................................................................................................. 1
Business Rule Framework plus ........................................................................................................... 2
1. PREREQUISITES........................................................................................................................................ 4
1.1.1 SAP System Access ................................................................................................................................................. 4
1.1.2 Authorizations........................................................................................................................................................ 6

2. STEPS BY STEPS........................................................................................................................................ 6
2.1.1 Create BRFplus application .................................................................................................................................... 6
2.1.2 Create BRFplus function and the rules................................................................................................................... 7
2.1.2.1 Create Rule #1 ................................................................................................................................................. 15
2.1.2.2 Create Rule #2 ................................................................................................................................................. 25
2.1.2.3 Create Rule #3 ................................................................................................................................................. 41
2.1.3 Simulate BRFplus function ................................................................................................................................... 48
2.1.4 Call the BRFplus function in ABAP........................................................................................................................ 53

3. CONCLUSIONS ....................................................................................................................................... 56
APPENDIX ....................................................................................................................................... 57

www.rizing.com
INTRODUCTION

The purpose of this document is to have uniform program standards for the Rizing – Digital
Development Center team, and to provide guidelines and useful information for consultants in the SAP
environment pertaining specifically to Business Rule Framework plus.
Programming standards and guidelines are needed to ensure the quality of custom developments.
Throughout this document the words shall, should, and must are indicative of a need and hence
adherence to such requirements is mandatory.
The words can and may are indicative of a want and so are optional. Non-conformance to such
requirements will not be serious.

www.rizing.com 1
BUSINESS RULE FRAMEWORK PLUS

Business Rule Framework plus (BRFplus) is a webdynpro application delivered by SAP from Netweaver
7.0 onwards and it brings a new way to design and develop business rules outside from ABAP program.
BRFplus consists of User Interface (UI), rules repository and a rules engine.

From a technical point of view, the most common use case for BRFplus that we run into is the
implementation of custom business logic in user-exits and enhancements. In fact, nowadays BRFplus is
our default approach for implementing custom business logic in such context, which can be described at
a high-level with 2 steps:

1. Creating a function within BRFplus that takes certain inputs, processes them through the
necessary business logic, and then produces the derived outputs
2. Calling the BRFplus function created in prior step via ABAP in a user-exit, enhancement, BAdI,
custom program, etc.

Architecture in nutshell

Application

A BRFplus application object is a container of different BRFplus objects. The application object type is
located at the highest level in the classification hierarchy for objects. All objects must be assigned to an
application.

Some of the most commonly used object types within an application are briefly described below:

Function

A function creates the access for the calling business application by passing in contexts/input values to
process the expressions and rulesets that are associated within the called function. The result data object
will be returned to the calling business application.

www.rizing.com 2
Rulesets

Rulesets are a collection/grouping of rules. These rules are processed during runtime when the specific
function that they are assigned to is processed during a call to BRFplus. Instead of assigning an
expression to a function, it is also possible to assign any number of rulesets to a function. When the
function is called, all assigned rulesets are subsequently processed.

Expressions

Expressions form the “…building blocks of rules”. There are various expression types within BRFplus,
which enable the processing of a specific logic. For example, Decision tables are expression types that
enable the sequential processing of “IF…THEN” statements, whereas formulas allow the processing of
mathematical and logical rules and Loop statements repeat the processing of a set of rules, which can
include the processing of other expressions.

www.rizing.com 3
1. PREREQUISITES
In general, BRFplus functionality is available on any SAP NetWeaver based system at the appropriate
enhancement pack level.

1.1.1 SAP System Access

BRFplus Workbench application is accessible using sap transaction “BRF+” or “BRFPLUS”. A web
application will appear in a new browser window where you are basically set to utilize BRFplus in your
environment.

www.rizing.com 4
The workbench has two UI modes, Simple Mode and Expert Mode. Simple Mode is recommended for
the business user for only needed for administrative tasks, whereas Expert Mode is for the business
expert or developer to access to a number of additional tools needed for administrative or cleanup tasks.
There are also more technical functions available in Expert Mode.

In this example, we need to set User Mode to Expert Mode. Click on the button, choose “Expert
Mode” and save it. We need to re-open the BRFplus Workbench application once changed.

www.rizing.com 5
1.1.2 Authorizations

N/A.

2. STEPS BY STEPS
In this example, there will be 3 rules to be applied into transaction code “IE01” and “IE02” upon save for
cost center.
Rule #1: Cost Center must not be blank.
Rule #2: Cost Center must be valid and active based on its Validity End Date.
Rule #3: Cost Center's Company Code is the same as Functional Location's Company Code.
To express these rules, we will be using the basic BRFplus rule, formula expression and procedure call
expression.

2.1.1 Create BRFplus application

To start with, create a BRFplus application using transaction code “BRF+” or “BRFplus”. You may be
asked to enter username and password.
Then, create the application as shown in the figure below. Enter the application name and short text
about it. For Development package, use TMP if you don’t want to transport it. Otherwise you will be asked

www.rizing.com 6
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. Click “Create And Navigate To Object” button and activate it.

2.1.2 Create BRFplus function and the rules

In an application, we need to have a function. BRFplus functions enables the system to evaluate during
outlier detection and event generation. This function will be the one to be used in our ABAP program,
buttons, BADIs etc. It’s very similar to a Function Module or Class Methods.

www.rizing.com 7
In this figure, we can create a BRFplus function by clicking on the “Contained Objects” tab, choose Type
“Function” and click on the “Create Object” button. Enter the function name and short text about it. Then
click on the “Create and Navigate To Object” button.

There are 3 Operation Mode in function, which defines how rules are processed:
a) Functional Mode
Functional mode requires a top expression to be assigned to the function. During processing, the function
triggers and evaluates the top expression. The top expression can also invoke other expressions to derive
result value. Functional mode is used for more simple use cases with a clear output of the function.
b) Event Mode
The event mode offers a more flexible approach to rule execution. Event mode uses rulesets to trigger
processing instead of a top expression. The sequence of execution is based on the priority assigned to

www.rizing.com 8
the ruleset. Event mode is used for more complex use cases and for use cases where a result is not
needed.
c) Functional and Event mode
This is an approach that uses both the functional mode and event mode as strategy for business rule
processing. Basically, this approach uses a combination of direct call to expressions and ruleset
processing techniques. As with functional mode, assigning a top expression and a result data object is
mandatory. In addition, rulesets can be processed so that actions can be performed, thereby possibly
changing the context. At runtime, the function starts processing the assigned top expression. Once the
expression evaluation is finished, function execution continuous with the associated rulesets.
In this example, we are using the default “Event Mode”.

Under the Function object, we can create the Context Data Object elements (input parameters) like
Controlling Area, Cost Center and Functional Location as well as to the Result Data Object (output
parameter) status table. In this example, we have many elements, so we can choose to add multiple
elements.

www.rizing.com 9
We can choose either DDIC binding or self-defined elements. For self-defined elements, it could be text
or number.

www.rizing.com 10
Our result consists of one table which is a status table. Result Data Object could be also an element or
structure. But we are creating the status table as the result of our rules.

www.rizing.com 11
Click on the small menu-list button and select “Create”. Then select “Table” type and enter the function
name and short text about it. Under the Table Line Type, click on the “Create Structure from DB Table”
button and fill in pre-defined custom structure /VESTA/ZS_RULE.

www.rizing.com 12
Navigate to the data object table ET_STATUS and activate it.

www.rizing.com 13
After that we can create our rules and try to save the changes.

www.rizing.com 14
We can now switch to the tab “Assigned Rulesets” to create the rules.

2.1.2.1 Create Rule #1

In the newly created ruleset, create the first rule (Cost Center must not be blank). Click on the “Insert
Rule” button and choose “Create”.

www.rizing.com 15
Enter a description for the rule. Add an operation to process a new rule.

Enter name and click “Create And Navigate To Object” button. Save changes to ruleset
RS_COST_CENTER before proceeding to edit the new rule.

www.rizing.com 16
A rule consists of an embracing If condition tested by the system once the rule is triggered. Based on the
result of the condition, the rule performs a set of operations. The condition must have a True branch,
whereas the False branch is optional. You can assign a standard type, an existing context data object,
an existing expression or create a new expression as the condition. In this example, we are assigning
the existing context data object COSTCENTER and set the condition ‘is initial’.

www.rizing.com 17
Add an operation to assign value into object /VESTA/ZS_RULE-ICON. /VESTA/ZS_RULE is an internal
structure which will be added into the Result Data Object ET_STATUS.

www.rizing.com 18
Click on the object ICON and enter value to be assigned.

www.rizing.com 19
Perform the same steps to add the next operation to assign values to another object (MESSAGE and
RULE_ID). Click on the “Options” button  Assign Value to Context  Context  More.

www.rizing.com 20
Finally, add the operation to insert values in structure /VESTA/ZS_RULE into internal table ET_STATUS
and activate the rule.

www.rizing.com 21
www.rizing.com 22
www.rizing.com 23
Perform the same steps for Else statement.

www.rizing.com 24
2.1.2.2 Create Rule #2

Repeat the same steps to create Rule #2 (Cost Center must be valid and active based on its Validity End
Date). In this rule, we need to retrieve data from BAPI_COSTCENTER_GETDETAIL1 to get Valid From
and Valid To values. Hence, we need to create a structure BAPI_CCOUTPUTLIST and a table
BAPI_RETURN to store data from the BAPI.
Go to the right panel and right click on the ‘Data Object’ to create these new data objects.

www.rizing.com 25
Enter the DDIC element name, data object name and short description. Choose Binding Type “Binding
to Structure Type (DDIC)” and enter the DDIC Type Name. Navigate and activate the data object.

www.rizing.com 26
Repeat the same steps to create a table. We need to have a Table Line Type for the table. Hence, click
on the “Create Structure from DB Table” button and fill in structure BAPIRET2. Once clicked “OK”,
navigate and activate the data object.

www.rizing.com 27
The created data objects can be seen at the right panel under Data Object.

Next, go to the Ruleset to create the second rule.

www.rizing.com 28
Enter rule’s description. Add the condition where Cost Center is not blank. To call the
BAPI_COSTCENTER_GETDETAIL1, we need to create an expression. Click on AddProcess
ExpressionCreate.

Select Type “Procedure Call”.

www.rizing.com 29
Enter the Name for Procedure Call and its descriptions. Click on “Create And Navigate To Object” button.

www.rizing.com 30
Save the changes in Rule and click “OK” button to close the Rule window.

www.rizing.com 31
Select Call Type “Function Module” and fill in the Function Module Name
“BAPI_COSTCENTER_GETDETAIL1”. Save it. Then only we add the following Mapped Parameters:
• CONTROLLINGAREA (Importing parameter)
• COSTCENTER (Importing parameter)
• COSTCENTERDETAIL (Exporting parameter)
• RETURN (Changing Table)

www.rizing.com 32
Click on each of the Mapped Parameters to assign a parameter.

For the Result Data Object, choose BAPI_CCOUTPUTLIST. Activate the Procedure Call.

Once activated, click back to the ruleset and edit the rule. If the screen below prompt to add variables,
click “Cancel” as we are going to add the variables manually later.

www.rizing.com 33
Click “Show Ruleset Header” button to add variables to store the returned parameters
BAPI_CCOUTPUTLIST and BAPI_RETURN (though it is not assigned to Result Data Object, it is a
mandatory table from BAPI_COSTCENTER_GETDETAIL1).

www.rizing.com 34
Structure BAPI_CCOUTPUTLIST is assigned to operation automatically. Add variable BAPI_RETURN
as well.

www.rizing.com 35
Click to “Edit Rule” to add another rule under Procedure Call. In this rule, we will need to check on the
Cost Center validity.

Add a Formula expression in the If condition. Save it before moving to the new expression.

www.rizing.com 36
www.rizing.com 37
Create a Result Data Object and activate it.

Under the Formula Functions, choose the function “DT_GET_CURRENT_DATE” and activate it. Then,
back to the rule.

www.rizing.com 38
www.rizing.com 39
Add Low Value Operations VALID_FROM and High Value Operations VALID_TO.

www.rizing.com 40
Assign values to Then – Else conditions and activate it.

2.1.2.3 Create Rule #3

Repeat the same steps to create Rule #3 (Cost Center's Company Code is the same as Functional
Location's Company Code.). In this rule, we need to create another Procedure Call to call the
BAPI_FUNCLOC_GETDETAIL. In this BAPI, we need to return structure DATA_GENERAL_EXP for the
functional location’s company code. Hence, create a structure data object and activate it.

www.rizing.com 41
Next, create the Procedure Call expression by adding an operation under
PC_GET_COSTCENTER_DETAIL Procedure Call.

www.rizing.com 42
Enter the details and activate it.

www.rizing.com 43
Back to the ruleset, add variable DATA_GENERAL_EXP and save it. Variable DATA_GENERAL_EXP
is assigned to operation automatically.

Create a rule to check on the company code.

www.rizing.com 44
At the If condition, add the context Cost Center’s Company Code (BAPI_CCOUTPUTLIST-
COMP_CODE) is not equals to Functional Location’s Company Code (DATA_GENERAL_EXP-
COMP_CODE).

www.rizing.com 45
www.rizing.com 46
Arrange rule where Cost Center is blank to the above rule and activate it.

www.rizing.com 47
2.1.3 Simulate BRFplus function

Simulation tool in BRFplus allows user to analyze and test the logic with test data. This provides
tremendous flexibility to the users to test the rules before they are deployed into the productive system
environment.
To test, open the BRFplus Function and click on the “Simulation” button.

www.rizing.com 48
Click “Continue” button.

www.rizing.com 49
Enter values to contexts (input parameters) to run BRFplus and click “Execute” button. We may also save
the contexts as variants for future use.

The results shown in output parameter (ET_STATUS) will be shown below:

www.rizing.com 50
Processing Steps show details of all processing steps during function execution.

www.rizing.com 51
www.rizing.com 52
2.1.4 Call the BRFplus function in ABAP

To use these rules in ABAP, we can apply codes from the Code Template provided by SAP and
customize it. Go to BRFplus function and click on the “Create Code Template” button.

www.rizing.com 53
Define all the variables (input parameters) exactly as highlighted above and activate it.
In this example, BRF+ application is called when user clicks on “Save” button in transaction code IE01/IE02
(Equipment Create/Change). We apply these template codes in Customer Exit (Function module
EXIT_SAPMIEQ0_001).

www.rizing.com 54
www.rizing.com 55
To test, go to IE02 and fill in an Equipment. Once user clicks on the “Save” button, an ALV will be
displayed to show BRFplus validation statuses.

3. CONCLUSIONS
In conclusion, BRFplus is a new piece of functionality from SAP that makes it possible to manage all
custom business logic in a single place and in a re-usable way. For example, BRFplus functions are
easily re-usable, which greatly reduces the amount of duplicated business logic in your system. BRFplus
also offers various expressions that greatly speed up the development process for mapping business
rules, especially if those rules are complex. With BRFplus, all the custom business logic can be seen in
a single place, BRFplus transaction. Hence, we will not require to go through each of the programs, exits
and enhancements to adjust existing business rules. Even, simple adjustments to existing business rules
can be made by non-technical staff, without any need for ABAP changes.

www.rizing.com 56
APPENDIX

https://help.sap.com/erp_mdg_addon70/helpdata/en/9a/6b67ce7c26446483af079719edf679/frameset.h
tm
https://blogs.sap.com/2015/01/29/brf-plus-a-real-time-example/
http://sapbrfplus.blogspot.my/2015/06/creating-decision-table-in-brf-plus-by.html
https://www.scribd.com/document/273498969/How-to-Create-Formula-Functions-BRF-Plus
https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=428114190
https://blogs.sap.com/2015/10/18/brfplus-basics-how-to-call-a-function/

www.rizing.com 57

You might also like