How to… Better DECISION in Process Chain by using custom Formulas
Link to Content’s target Space :
SAP BW NetWeaver 2004s (BW7.0 or greater). For more information, visit the Business Intelligence homepage.
1. Business Scenario:
The business scenario for this document is that a customer has a need to use ‘Decision’ in Process chain based on Parameter set in custom table or based on output from different conditions and consistently uses the same in other Process chain decisions. In this example, Process chain takes decision based on entry maintained in TVARVC table. Instead of changing process chain, process chain executes steps based on TVARVC table entries maintained by Business or administrator.
2. Background Information:
Custom formulas are introduced into the ‘Decision Between Multiple Alternatives’ process type library of the Formula Builder by means of BAdi (Business Add-In) RSAR_CONNECTOR. The step by step solution that follows will demonstrate how to achieve this.
You can view the definition of the BAdi in transaction SE19 with BAdi name RSAR_CONNECTOR.
There are no prerequisites for this How-To-Guide, however the following reading material will help if you are not familiar with ABAP Classes and Method:
4. Step-By-Step Procedure
The guide starts you off by creating a BAdi implementation. This implementation will generate a class which we will use to store our custom functions (implemented as methods) in. When the custom methods are written and activated, we can then reference them in our BAdi implementation. Once linked, we will have them available in the Process Type ‘Decision’ in Process chain maintenance.
For this example, we will use TVARVC table entry which will decide what process flow/steps executed in Process chain.
4.1 Create Implementation for BAdi RSAR_CONNECTOR.
- Go to t-code SE19 -> Create Implementation -> Classic BAdi. Give BAdi Name as ‘RSAR_CONNECTOR’ and click on ‘Create Impl’ button.
- Provide name of Implementation and click ‘OK’
- This will take you to the definition of the implementation. Provide suitable description to the Implementation.
- Press the activate button on the toolbar in order to activate your implementation and its underlying objects.
Remember the name of the implementing class you can see in the screenshot (ZCL_IM_DEMO_CUSTOM_FUNC), we will use this later to store our methods.
4.2 Create custom methods i.e. custom formula
- Go to transaction SE24 in order to edit Class ZCL_IM_DEMO_CUSTOM_FUNC. Alternatively, instead of using the class generated from creating the implementation, you could implement your own class with methods.
- Press ‘Change’ button. On the ‘Methods’ tab you can implement as many custom methods as you wish. In the below screenshot, 1 custom method is visible: C_DEMO_FUNC.
- C_DEMO_FUNC is given name to method. Choose Level as ‘Static Method’, Visibility as ‘Public’ and give suitable Description.
- Once your method has a name and attributes, proceed to defining its parameters by pressing the ‘Parameters’ button.
- Maintain Importing and Exporting Parameter as shown below. Remember that, you can have importing, exporting or returning parameter, no changing parameter allowed. Most important thing is, you can have only one Exporting parameter.
- Once you maintained Parameters, click on ‘Methods’.
- Double-click on the Method name (C_DEMO_FUNC) to view method code.
- Enter code between the sections “METHOD <method name>. ENDMETHOD.” Remember to use your parameters exactly as you have named them on the parameter definition screen for your method. In the screenshot, you will see that we pass the ‘I_RULE_NAME’ to ‘where-clause of SELECT statement performed on TVARVC table to return ‘E_STATUS’.
- Activate your method.
4.3 Integrate custom methods into your implementation
- Go back to transaction SE19, and in the ‘Edit Implementation’ section, change the radio button to ‘Classic BAdi’ and enter BAdi name ‘ZDEMO_CUSTOM_FUNC’.
- Click on ‘Change’ button.
- Press “CTRL+F4” to deactivate your implementation.
- Double-click on the ‘GET’ method on the ‘Interface’ tab in order to incorporate your custom methods as formulas
The ‘GET’ method allows us to do two things:
• Firstly we get to create new categories for custom formulas (optional)
• Secondly we get to assign custom formulas to those new groupings or alternatively to the default grouping.
- Initially the method will be empty.
- Write below code –
DATA: L_FUNCTION TYPE SFBEOPRND.
L_FUNCTION–CLASS = ‘ZCL_IM_DEMO_CUSTOM_FUNC’.
L_FUNCTION–METHOD = ‘C_DEMO_FUNC’.
L_FUNCTION–TECH_NAME = ‘C_DEMO_FUNC’.
L_FUNCTION–DESCRIPTN = ‘Demo Rule’.
APPEND L_FUNCTION TO C_OPERANDS.
- When I_KEY is populated as ‘CUSTOM’, it is referring to a category name for customer use in which you want to place your custom formulas. In this section appending to c_operands creates a new function within that category.
- CLASS – this is class you defined above where the formula method is implemented
- METHOD- The method which you have defined in your class to define your formula.
- TECH_NAME- Give technical name to your Function. This should always start with C_ and should be in CAPITAL letters.
- DESCRIPTN- Give description to your function.
- The TECH_NAME and DESCRIPTN will appear in Formula Builder of the Decision process maintenance screen.
- ‘CUSTOM’ is predefined category provided to user to categorize their custom defined functions in Formula Builder.
- Activate the GET method using the activate button on the toolbar.
- Go back one screen and activate your implementation.
4.3 View in Formula Builder of DECISION of the process chain
- Go to Maintenance screen of the Process Type ‘ Decision’ in Process Chain.
- Click on ‘Create’
- Give Long Description
- In right hand side, in ALL Function drop down, you will see – ‘User Defined Functions’.
- Note: If no single custom function created before, you will not have this option available. As soon as you create your first function, it will start displaying this category. This category is nothing but ‘CUSTOM’
- Select ‘User-Defined Function’, it will show you your created function as below-
- According to your definition, use it in ‘Formula Builder’.
- C_DEMO_FUNC is your custom function
- ‘TEST_RULE’ = Exporting parameter to the function
- Output of the function is compared with right hand side string.
Important Note: This Function will be reusable. This can be viewed in Transformation Formula Builder as well.
This is how you can use your custom function to take better decision in Process chain.
Hope this guide will help you.