You are on page 1of 20

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: Anurag Krishna Dev


Company: Infosys technologies limited
Created on: 19 April 2009

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.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2009 SAP AG 1
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 2
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 3
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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

pencil symbol which


signifies that start routine is
maintained

Figure - 3

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 4
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

Routine for key Figureures or characteristics


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

change to pencil symbol which


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

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 5
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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):

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 6
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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):

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 7
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 8
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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

Click on expert routine to go to create


the expert routine.

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.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 9
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 10
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

Step 2 – Write expert routine


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 TYPE /BI0/OIFISCYEAR,
* InfoObject: 0FISCPER3 Posting period.
FISCPER3 TYPE /BI0/OIFISCPER3,
* InfoObject: 0FISCVARNT Fiscal year variant.
FISCVARNT TYPE /BI0/OIFISCVARNT,
* InfoObject: 0PLANT Plant.
PLANT TYPE /BI0/OIPLANT,
* InfoObject: ZMERCHND Merchandise.
/BIC/ZMERCHND TYPE /BIC/OIZMERCHND,
* InfoObject: Z_ABS_PLN Average Bill Size Planned.
/BIC/Z_ABS_PLN TYPE /BIC/OIZ_ABS_PLN,
* InfoObject: Z_CNP_PLN Conversion Percentage Planned.
/BIC/Z_CNP_PLN TYPE /BIC/OIZ_CNP_PLN,
* InfoObject: Z_WLK_PLN No of Walkin Planned.
/BIC/Z_WLK_PLN TYPE /BIC/OIZ_WLK_PLN,

* InfoObject: ZSAL_PLN Planned Sales.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 11
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

/BIC/ZSAL_PLN TYPE /BIC/OIZSAL_PLN,


* InfoObject: 0VERSION Version.
VERSION TYPE /BI0/OIVERSION,
* InfoObject: 0CURRENCY Currency Key.
CURRENCY TYPE /BI0/OICURRENCY,
* Field: RECORD.
RECORD TYPE RSARECORD,
END OF _ty_s_SC_1.
TYPES:
_ty_t_SC_1 TYPE STANDARD TABLE OF _ty_s_SC_1
WITH NON-UNIQUE DEFAULT KEY.
TYPES:
BEGIN OF _ty_s_TG_1,
* InfoObject: 0FISCYEAR Fiscal year.
FISCYEAR TYPE /BI0/OIFISCYEAR,
* InfoObject: 0FISCPER3 Posting period.
FISCPER3 TYPE /BI0/OIFISCPER3,
* InfoObject: 0FISCVARNT Fiscal year variant.
FISCVARNT TYPE /BI0/OIFISCVARNT,
* InfoObject: 0PLANT Plant.
PLANT TYPE /BI0/OIPLANT,
* InfoObject: ZMERCHND Merchandise.
/BIC/ZMERCHND TYPE /BIC/OIZMERCHND,
* InfoObject: Z_ABS_PLN Average Bill Size Planned.
/BIC/Z_ABS_PLN TYPE /BIC/OIZ_ABS_PLN,
* InfoObject: Z_CNP_PLN Conversion Percentage Planned.
/BIC/Z_CNP_PLN TYPE /BIC/OIZ_CNP_PLN,
* InfoObject: Z_WLK_PLN No of Walkin Planned.
/BIC/Z_WLK_PLN TYPE /BIC/OIZ_WLK_PLN,
* InfoObject: ZSAL_PLN Planned Sales.
/BIC/ZSAL_PLN TYPE /BIC/OIZSAL_PLN,
* InfoObject: 0VERSION Version.
VERSION TYPE /BI0/OIVERSION,
* InfoObject: 0CURRENCY Currency Key.
CURRENCY TYPE /BI0/OICURRENCY,
* Field: RECORD.
RECORD TYPE RSARECORD,
END OF _ty_s_TG_1.
TYPES:
_ty_t_TG_1 TYPE STANDARD TABLE OF _ty_s_TG_1
WITH NON-UNIQUE DEFAULT KEY.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 12
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

*$*$ 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 *

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 13
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

... "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> TYPE _ty_s_SC_1.
DATA:
RESULT_FIELDS TYPE _ty_s_TG_1.
*$*$ begin of routine - insert your code only below this line *-*
DATA : source_pkg LIKE LINE OF SOURCE_PACKAGE[],
result_pkg LIKE LINE OF RESULT_PACKAGE[],
fisc_yr(4) TYPE n,
w_sales(10) TYPE p DECIMALS 3 ,
w_walkin TYPE i.
IF NOT SOURCE_PACKAGE[] IS INITIAL.
fisc_yr = '2009'.
clear : temp_pln_walkin .
LOOP AT SOURCE_PACKAGE[] INTO source_pkg
WHERE
fiscper3 NE space AND
fiscyear = fisc_yr AND
/bic/zmerchnd NE space AND
plant NE space AND
version = 'V01'.
CLEAR : RESULT_PACKAGE[],
wa_pln_walkin.
wa_pln_walkin-fiscper3 = source_pkg-fiscper3.
wa_pln_walkin-fiscyear = source_pkg-fiscyear.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 14
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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
*----------------------------------------------------------------------*

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 15
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

*
* 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

Now save and activate the transformation.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 16
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

Step 3 – Create DTP and Execute it


In the next step create the DTP to execute this expert routine between source plan cube and target
reporting cube.

Figure - 11

Debugging Expert Routine


For debugging of this expert routine we need to change the processing mode of this DTP
From

To

After changing the processing mode we can select the desired break point for debugging

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 17
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 18
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

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.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 19
Implementation and usage of Expert routine in SAP Net weaver BI 7.0.

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


© 2008 SAP AG 20

You might also like