Skip to Content

Link to Content’s target Space :

http://scn.sap.com/community/data-warehousing

Applies to:

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.

3. Pre-requisites

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:

Reference 1 – ABAP Business Development and Service Provisioning

Reference 2 – Creating, Editing, and Deleting Enhancement Implementations


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’

Implementation Name.JPG

    • This will take you to the definition of the implementation. Provide suitable description to the Implementation.

Implementation Name-02.JPG

    • 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.

               SE24-01.JPG

    • 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.

SE24-02.JPG

    • 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.

SE24-03.JPG

    • 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’.

SE24-04.JPG

    • 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.

    • 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_FUNCTIONCLASS      = ‘ZCL_IM_DEMO_CUSTOM_FUNC’.

                 L_FUNCTIONMETHOD     = ‘C_DEMO_FUNC’.

                 L_FUNCTIONTECH_NAME  = ‘C_DEMO_FUNC’.

                 L_FUNCTIONDESCRIPTN  = ‘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.

Decision-01.JPG

    • Click on ‘Create’

Decision-02.JPG

    • 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’

Decision-03.JPG

    • Select ‘User-Defined Function’, it will show you your created function as below-

Decision-04.JPG

    • According to your definition, use it in ‘Formula Builder’.

Decision-05.JPG

      • 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.

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Daniel Klein

    ‘TEST_RULE’ = Exporting parameter to the function

    caused a bit confusion in my opinion.

    I would change the explanation to

    ‘TEST_RULE’ = Importing parameter of your custom function

    (0) 
    1. Yogesh Patil Post author

      I hope this document helped you.  If you look at SAP’s Function module or Class/Methods, the passing values are export parameters and return values are import parameters.

      Here,  C_DEMO_FUNC accepts ‘Test_Rule’ as a input and returns value based on input string ‘Test_Rule’. So in SAP’s definition, it is export parameter.

      I hope this will satisfy your query 🙂

      (0) 

Leave a Reply