Взято отсюда, но на всякий случай, продублирую:
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
- Note:
- 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.
- Note:
- Initially the method will be empty.
- Write below code -
METHOD IF_EX_RSAR_CONNECTOR~GET.
DATA: L_FUNCTION TYPE SFBEOPRND.
CASE I_KEY.
WHEN 'CUSTOM'.
CLEAR: L_FUNCTION.
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.
ENDCASE.
ENDMETHOD.
- Here-
- 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'.
- Where-
- 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.
Комментариев нет:
Отправить комментарий