Professional Documents
Culture Documents
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 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
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.
Figure - 3
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.
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.
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
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.
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.
*$*$ begin of global - insert your declaration only below this line *-*
* *******************************************************************
* GLOBAL DATA DECLARATION
* *******************************************************************
TYPES: BEGIN OF int_pln_walkin ,
Structure Declaration of Internal
fiscper3 TYPE /bi0/oifiscper3, table of storing Intermediate
fiscvarnt TYPE /bi0/oifiscvarnt, Results
fiscyear TYPE /bi0/oifiscyear,
plant TYPE /bi0/oiplant,
merchandise TYPE /bic/oizmerchnd,
version TYPE /bi0/oiversion,
zsal_pln TYPE /bic/oizsal_pln,
z_abs_pln TYPE /bic/oiz_abs_pln,
z_cnp_pln TYPE /bic/oiz_cnp_pln,
z_wlk_pln TYPE /bic/oiz_wlk_pln,
END OF int_pln_walkin.
DATA : temp_pln_walkin TYPE STANDARD TABLE OF int_pln_walkin,
wa_pln_walkin TYPE int_pln_walkin.
*$*$ end of global - insert your declaration only before this line *-*
METHODS
expert_routine
IMPORTING
request type rsrequest
datapackid type rsdatapid
SOURCE_PACKAGE type _ty_t_SC_1
log type ref to cl_rsbm_log_cursor_step
EXPORTING
RESULT_PACKAGE type _ty_t_TG_1.
METHODS
inverse_expert_routine
IMPORTING
i_th_fields_outbound TYPE rstran_t_field_inv
i_r_selset_outbound TYPE REF TO cl_rsmds_set
i_r_universe_inbound TYPE REF TO cl_rsmds_universe
CHANGING
c_th_fields_inbound TYPE rstran_t_field_inv
c_r_selset_inbound TYPE REF TO cl_rsmds_set
c_exact TYPE rs_bool.
ENDCLASS. "routine DEFINITION
*$*$ begin of 2nd part global - insert your code only below this line *
wa_pln_walkin-fiscvarnt = source_pkg-fiscvarnt.
wa_pln_walkin-plant = source_pkg-plant.
wa_pln_walkin-merchandise = source_pkg-/bic/zmerchnd.
wa_pln_walkin-version = 'V02'.
wa_pln_walkin-zsal_pln = source_pkg-/bic/zsal_pln.
COLLECT wa_pln_walkin INTO temp_pln_walkin.
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 = wa_pln_walkin-fiscyear
plant = wa_pln_walkin-plant
/bic/zmerchnd = wa_pln_walkin-merchandise
version = wa_pln_walkin-version.
if sy-subrc = 0 .
CLEAR : result_pkg .
result_pkg-fiscper3 = wa_pln_walkin-fiscper3.
result_pkg-fiscyear = wa_pln_walkin-fiscyear.
result_pkg-fiscvarnt = wa_pln_walkin-fiscvarnt.
result_pkg-plant = wa_pln_walkin-plant.
result_pkg-/bic/zmerchnd = wa_pln_walkin-merchandise.
result_pkg-version = 'V100'.
result_pkg-/bic/zsal_pln = wa_pln_walkin-zsal_pln.
result_pkg-currency = 'INR'.
result_pkg-/bic/z_abs_pln = source_pkg-/bic/z_abs_pln.
result_pkg-/bic/z_cnp_pln = source_pkg-/bic/z_cnp_pln.
w_sales = ( wa_pln_walkin-zsal_pln * 100 ) .
w_walkin = ( source_pkg-/bic/z_abs_pln *
source_pkg-/bic/z_cnp_pln ).
result_pkg-/bic/z_wlk_pln = ( w_sales / w_walkin ).
APPEND result_pkg TO RESULT_PACKAGE.
ENDIF.
ENDLOOP.
ENDIF.
*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "expert_routine
*----------------------------------------------------------------------*
* Method inverse_expert_routine
*----------------------------------------------------------------------*
*
* 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.
*
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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. "inverse_expert_routine
ENDCLASS. "routine IMPLEMENTATION
Figure - 11
To
After changing the processing mode we can select the desired break point for debugging
Figure - 12
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
http://www.help.sap.com
For more information, visit the Business Intelligence homepage.