Implementation and Usage of Expert Routine in SAP Net Weaver BI 7.0
Implementation and Usage of Expert Routine in SAP Net Weaver BI 7.0
Applies to:
This article applies to SAP BI 7.0. For more information, visit the Business Intelligence homepage.
Summary
This document provides the overview of all the routines available in transformation in BI 7.0 with special focus on the possible scenarios for usage of expert routine and how to implement the same. Author: Company: Created on:
Author Bio
Anurag krishna dev is an SAP certified solution consultant and working at Infosys technologies. He has been involved in SAP BI consulting practice for 3 years now. He has expertise in executing implementation and support projects for multiple clients.
Table of Contents
Introduction .........................................................................................................................................................3 Start routine ........................................................................................................................................................4 Routine for key Figureures or characteristics .................................................................................................5 End routine......................................................................................................................................................5 Expert routine..................................................................................................................................................5 Business scenario ...........................................................................................................................................6 Technical Solution ..............................................................................................................................................8 Step 1 Create transformation.......................................................................................................................8 Step 2 Write expert routine ........................................................................................................................11 Step 3 Create DTP and Execute it.............................................................................................................17 Debugging Expert Routine................................................................................................................................17 Step 4 Check the data loaded....................................................................................................................18 Disclaimer and Liability Notice..........................................................................................................................20
Introduction
This article explains about the different routines available in transformation in BI 7.0 and how they are structured in main transformation program. The document also elaborates the business scenarios where these routines can be leveraged to implement complex transformation rules. Special focus is given on expert routine with an example business scenario.
Routines in transformation
Routines are local ABAP classes that consist of a predefined definition area and an implementation area. The TYPES for the inbound and outbound parameters and the signature of the routine (ABAP method) are stored in the definition area. The actual routine is created in the implementation area. ABAP object statements are available in the coding of the routine. Upon generation, the coding is embedded in the local class of the transformation program as the method. As of Net Weaver release 2004s following four types of routines are available in transformation 1. Start routine 2. Routine for key Figureures and characteristics (transfer rule routine) 3. End routine 4. Expert routine Following Figureure depicts the position of these routine in dataflow
Figureure 1 These routines are the components of main transformation program; following Figureure shows the structure of main transformation program with different components
Figure - 2
Start routine
The start routine is run for each data package at the start of the transformation. The start routine has a table in the format of the source structure as input and output parameters. It is used to perform preliminary calculations and store these in a global data structure or in a table. This structure or table can be accessed from other routines. You can modify or delete data in the data package.
Click here to maintain the start routine. After maintaining it, the new symbol will change to
Figure - 3
This routine is available as a rule type; you can define the routine as a transformation rule for a key Figureure or a characteristic. The input and output values depend on the selected field in the transformation rule.
Figure - 4
End routine
An end routine is a routine with a table in the target structure format as input and output parameters. You can use an end routine to post process data after transformation on a package-by-package basis. For example, you can delete records that are not to be updated, or perform data checks. As described in the Figure - 1, the end routine is executed at end of the main transformation program.
Go here to maintain the end routine. After maintaining it, the new symbol will
pencil symbol which change to signifies that Start Routine is maintained.While in display mode the existence of the End routine will be signified by the specs symbol .
Figure - 7
Expert routine
This type of routine is only intended for use in special cases. You can use the expert routine if there are not sufficient functions to perform a transformation. The expert routine should be used as an interim solution until the necessary functions are available in the standard routine. You can use this to program the transformation yourself without using the available rule types. You must implement the message transfer to the monitor yourself. If you have already created transformation rules, the system deletes them once you have created an expert routine. This is also to remember that If the target of the transformation is a Data store object, key Figureures are updated by default with the aggregation behavior Overwrite (MOVE).
Figure 5
Figure 6
Business scenario
To understand the potential and know how of expert routine , we will take a business scenario of a major retail company XYZ Retail. Two types of business planning are done at XYZ Retail. First is sales planning which is done across the plant (Retail Outlet) and merchandise at fiscal period level. The version for this planning is V01. Second is outlet planning in which the planning is done for average bill size, conversion % and No of Walk-In, this planning is done at fiscal year level. The version for this planning is V02. The relationship among the Figureures is following Total sales = (Average bill size) * (Conversion %)*( Total Walk-in) In SAP BW system of XYZ Retail the planned data is stored in a planning cube Z_SAL_PLAN. And the planned data stored in this cube is like below (Table 1.1):
Table 1.1 For a new reporting requirement we need to calculate the planned values of walk-in at fiscal period level and these values should be stored in a reporting cube at version V10. Taking the above mentioned relationship among the Figureure we have to calculate the monthly values of planned walk-in. Since average bill size and Conversion % are not the relative Figureures so we can replicate their yearly value to month level. Now we have the values of planned sales, average bill size, and conversion % at fiscal period level Now our task is to calculate and load the values of planned walk-in at fiscal period level by using the formula Planned walk-in = Total sales / (Average bill size) * (Conversion %) And finally the target data should be loaded in the reporting cube Z_SAL_REP in the following format (Table 1.2):
Table 1.2
Technical Solution
In order to technically realize this business scenario we will be using the expert routine to define this transformation between the source planning cube and target reporting cube. The structure of both source and target cube is same which is shown in Figure 7
Figure - 7
We will follow the following step to understand how to implement the Expert routine in transformation.
Step 1 Create transformation
Go to the context menu of source Info cube Z_SAL_PLN and select Create transformation ,provide the target detail of transformation as shown in Figure 8 and click on continue
Figure 8 In the subsequent screen the system will propose the transfer rule between the source and target cube, we need to ignore that and go to edit menu on top of the screen and select expert routine as shown in Figure 9
Figure - 9 As we discussed previously that once the expert routine is maintained between the source and target then system deletes all other existing transfer rule between these source and target. The same is happening here; once you click on expert routine the system will prompt you for confirmation for deletion of existing transformation, we need to say YES.
Figure -10 The subsequent window is the place where we have to write our expert routine. Before going ahead for writing the Expert routine, below are some points that we need to keep in mind: 1. Between *$*$ begin of global ... and *$*$ end of global ... you can define the global data declarations 'CLASS DATA'. These are available in all routines. Data declarations with DATA can only be accessed in the current package. This means that you can use intermediate results in other routines, for example, or reuse results when you call a routine again at a later time. When you perform serial loads, one process instance is used for the entire request. In this case, data with the CLASS DATA data declaration can be accessed for the entire request (all packages). Several process instances are used when you perform parallel loads. A single process instance can be used a more than once, depending on the number of data packages to be processed and the number of available process instances. This means that with parallel loads, data with the 'CLASS DATA' data declaration is not initialized for each data package and may still contain data from predecessor packages.For this reason, use 'CLASS DATA' or 'DATA' for the global data, depending on the scenario 2. In the routine editor, a maximum of 72 characters per line are currently permitted. Any additional characters are cut off when you save. 3. Enter your program code for the routine between *$*$ begin of routine ... and *$*$ end of routine. 4. Do not use a SAP COMMIT (ABAP statement: COMMIT WORK) in your coding. When this statement is executed, the cursor that is used from the source for reading is lost. Use a DB COMMIT (call function module DB_COMMIT) instead or avoid using such COMMITs altogether. 5. Check the syntax of your routine. 6. Save the routine. You end the maintenance session for the routine by leaving the editor.
In the next step write following expert routine to implement our business scenario. The routine is explained for further understanding
PROGRAM trans_routine. *---------------------------------------------------------------------* * CLASS routine DEFINITION *---------------------------------------------------------------------* **---------------------------------------------------------------------* CLASS lcl_transform DEFINITION. PUBLIC SECTION. * Attributs DATA: p_check_master_data_exist TYPE RSODSOCHECKONLY READ-ONLY, ** * Instance for getting request runtime attributs; Available information: Refer to methods of interface 'if_rsbk_request_admintab_view' p_r_request TYPE REF TO if_rsbk_request_admintab_view READ-ONLY. PRIVATE SECTION. TYPE-POOLS: rsd, rstr. * Rule specific types TYPES: BEGIN OF _ty_s_SC_1, * * * * * * * * InfoObject: 0FISCYEAR Fiscal year. FISCYEAR FISCPER3 FISCVARNT PLANT /BIC/ZMERCHND /BIC/Z_ABS_PLN /BIC/Z_CNP_PLN /BIC/Z_WLK_PLN * TYPE /BI0/OIFISCYEAR, TYPE /BI0/OIFISCPER3, TYPE /BI0/OIFISCVARNT, TYPE /BI0/OIPLANT, TYPE /BIC/OIZMERCHND, TYPE /BIC/OIZ_ABS_PLN, TYPE /BIC/OIZ_CNP_PLN, TYPE /BIC/OIZ_WLK_PLN, InfoObject: 0FISCPER3 Posting period. InfoObject: 0FISCVARNT Fiscal year variant. InfoObject: 0PLANT Plant. InfoObject: ZMERCHND Merchandise. InfoObject: Z_ABS_PLN Average Bill Size Planned. InfoObject: Z_CNP_PLN Conversion Percentage Planned. InfoObject: Z_WLK_PLN No of Walkin Planned.
/BIC/ZSAL_PLN * * * VERSION CURRENCY Field: RECORD. RECORD END TYPES: _ty_t_SC_1 TYPES: BEGIN OF _ty_s_TG_1, * * * * * * * * * * * *
InfoObject: 0FISCYEAR Fiscal year. FISCYEAR FISCPER3 FISCVARNT PLANT /BIC/ZMERCHND /BIC/Z_ABS_PLN /BIC/Z_CNP_PLN /BIC/Z_WLK_PLN /BIC/ZSAL_PLN VERSION CURRENCY Field: RECORD. RECORD END TYPES: _ty_t_TG_1 TYPE STANDARD TABLE OF _ty_s_TG_1 WITH NON-UNIQUE DEFAULT KEY. TYPE RSARECORD, OF _ty_s_TG_1. TYPE /BI0/OIFISCYEAR, TYPE /BI0/OIFISCPER3, TYPE /BI0/OIFISCVARNT, TYPE /BI0/OIPLANT, TYPE /BIC/OIZMERCHND, TYPE /BIC/OIZ_ABS_PLN, TYPE /BIC/OIZ_CNP_PLN, TYPE /BIC/OIZ_WLK_PLN, TYPE /BIC/OIZSAL_PLN, TYPE /BI0/OIVERSION, TYPE /BI0/OICURRENCY, InfoObject: 0FISCPER3 Posting period. InfoObject: 0FISCVARNT Fiscal year variant. InfoObject: 0PLANT Plant. InfoObject: ZMERCHND Merchandise. InfoObject: Z_ABS_PLN Average Bill Size Planned. InfoObject: Z_CNP_PLN Conversion Percentage Planned. InfoObject: Z_WLK_PLN No of Walkin Planned. InfoObject: ZSAL_PLN Planned Sales. InfoObject: 0VERSION Version. InfoObject: 0CURRENCY Currency Key.
*$*$ begin of global - insert your declaration only below this line * GLOBAL DATA DECLARATION TYPES: BEGIN OF int_pln_walkin , fiscper3 fiscvarnt fiscyear plant version zsal_pln z_abs_pln z_cnp_pln z_wlk_pln TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE /bi0/oifiscper3, /bi0/oifiscvarnt, /bi0/oifiscyear, /bi0/oiplant, /bic/oizmerchnd, /bi0/oiversion, /bic/oizsal_pln, /bic/oiz_abs_pln, /bic/oiz_cnp_pln, /bic/oiz_wlk_pln, TYPE STANDARD TABLE OF int_pln_walkin,
*-*
* ******************************************************************* * *******************************************************************
merchandise TYPE
END OF int_pln_walkin. DATA : temp_pln_walkin wa_pln_walkin METHODS expert_routine IMPORTING request datapackid SOURCE_PACKAGE log EXPORTING RESULT_PACKAGE METHODS inverse_expert_routine IMPORTING i_th_fields_outbound i_r_selset_outbound i_r_universe_inbound CHANGING c_th_fields_inbound c_r_selset_inbound c_exact ENDCLASS. TYPE rstran_t_field_inv TYPE REF TO cl_rsmds_set TYPE rs_bool. "routine DEFINITION * TYPE rstran_t_field_inv TYPE REF TO cl_rsmds_set TYPE REF TO cl_rsmds_universe type _ty_t_TG_1. type rsrequest type rsdatapid type _ty_t_SC_1 type ref to cl_rsbm_log_cursor_step TYPE int_pln_walkin. *-*
*$*$ end of global - insert your declaration only before this line
*$*$ begin of 2nd part global - insert your code only below this line
... "insert your code here *$*$ end of 2nd part global - insert your code only before this line * CLASS routine IMPLEMENTATION * *---------------------------------------------------------------------* *---------------------------------------------------------------------* **---------------------------------------------------------------------* CLASS lcl_transform IMPLEMENTATION. *----------------------------------------------------------------------* * * * * Method expert_routine Calculation of result package via expert routine -> package of source segments <- result package METHOD expert_routine. *=== Segments === FIELD-SYMBOLS: <SOURCE_FIELDS> DATA: RESULT_FIELDS DATA : source_pkg result_pkg fisc_yr(4) w_sales(10) w_walkin fisc_yr = '2009'. TYPE _ty_s_TG_1. *-* LIKE LINE OF SOURCE_PACKAGE[], LIKE LINE OF RESULT_PACKAGE[], TYPE n, TYPE p DECIMALS 3 , TYPE i. *$*$ begin of routine - insert your code only below this line TYPE _ty_s_SC_1. *----------------------------------------------------------------------* *----------------------------------------------------------------------*
*----------------------------------------------------------------------*
IF NOT SOURCE_PACKAGE[] IS INITIAL. clear : temp_pln_walkin . LOOP AT SOURCE_PACKAGE[] INTO source_pkg WHERE fiscper3 fiscyear plant version NE = NE = space AND fisc_yr AND space AND space AND 'V01'.
/bic/zmerchnd NE
wa_pln_walkin-fiscvarnt wa_pln_walkin-plant wa_pln_walkin-merchandise wa_pln_walkin-version wa_pln_walkin-zsal_pln ENDLOOP. CLEAR: source_pkg, result_pkg, wa_pln_walkin.
LOOP AT temp_pln_walkin INTO wa_pln_walkin . READ TABLE SOURCE_PACKAGE[] INTO source_pkg WITH KEY fiscyear plant /bic/zmerchnd version if sy-subrc = 0 . CLEAR : result_pkg . result_pkg-fiscper3 result_pkg-fiscyear result_pkg-fiscvarnt result_pkg-plant result_pkg-/bic/zmerchnd result_pkg-version result_pkg-/bic/zsal_pln result_pkg-currency result_pkg-/bic/z_abs_pln result_pkg-/bic/z_cnp_pln w_sales w_walkin result_pkg-/bic/z_wlk_pln ENDIF. ENDLOOP. ENDIF. *$*$ end of routine - insert your code only before this line ENDMETHOD. * "expert_routine *-* = = = = = = = = = = = = = wa_pln_walkin-fiscper3. wa_pln_walkin-fiscyear. wa_pln_walkin-fiscvarnt. wa_pln_walkin-plant. wa_pln_walkin-merchandise. 'V100'. wa_pln_walkin-zsal_pln. 'INR'. source_pkg-/bic/z_abs_pln. source_pkg-/bic/z_cnp_pln. ( wa_pln_walkin-zsal_pln ( source_pkg-/bic/z_abs_pln * ( w_sales / w_walkin ). * 100 ) . = = = = wa_pln_walkin-fiscyear wa_pln_walkin-plant wa_pln_walkin-merchandise wa_pln_walkin-version.
* * * * * * * * * * *----------------------------------------------------------------------* * *----------------------------------------------------------------------* METHOD inverse_expert_routine. *$*$ begin of inverse routine - insert your code only below this line*-* ... "insert your code here *$*$ end of inverse routine - insert your code only before this line *-* ENDMETHOD. ENDCLASS. "inverse_expert_routine "routine IMPLEMENTATION This subroutine needs to be implemented only for direct access (for better performance) and for the Report/Report Interface (drill through). The inverse routine should transform a projection and a selection for the target to a projection and a selection for the source, respectively. If the implementation remains empty all fields are filled and all values are selected.
In the next step create the DTP to execute this expert routine between source plan cube and target reporting cube.
Figure - 11
To
After changing the processing mode we can select the desired break point for debugging
Figure - 12
Step 4 Check the data loaded
In the final step we will check whether the data loaded in the reporting cube is up to our expectation or not.
Figure 13 As we can see here that the data loaded in the target reporting cube is as per the expectation.
Related contents
Routines in transformation How to load Gas-Industry Flat File Via Expert routine Writing Routines in Transformation