Anda di halaman 1dari 21

How to Automate Loading

Hierarchies from R3 / ECC

Applies to:
SAP Netweaver 2004 (BW 3.x), Netweaver 2004S, EHP1 and EHP2 (BW 7.x). For more information, visit the
EDW homepage.

Summary
0ACCOUNT, 0PROFIT_CTR and 0STKEYFIG are some infoobjects that have hierarchies. Unfortunately, 1
infopackage is to load 1 hierarchy only.
If you have 500 hierarchies for all of them above, you have to manually click execute 500 times, or create
500 InfoPackages in process chain.
This solution will help you automate loading those hierarchies. It is BI (10%) and ABAP (90%) solution.

Author: Dex Rembrandt Soepriyadi


Company: PT EBS Solusi Pro Satu
Created on: 28 March 2011

Author Bio
Dex has 15 years IT experience. First 8 years as programmer / system analyst. Remaining as SAP
consultant and his core skill is SAP BW + BO module.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 1
How to Automate Loading Hierarchies from R3 / ECC

Table of Contents
Purpose............................................................................................................................................................... 3
Case Study / Scenario sample ........................................................................................................................... 3
Solution ............................................................................................................................................................... 3
1: Using Standard SAP Function Module ....................................................................................................... 3
2: Creating Custom infoPackage with Embedded ABAP Code ...................................................................... 4
3: Call above Infopackage using BAPI Standard Function Module. BAPI_IPAK_START .............................. 4
4: Utilize TVARV Table ................................................................................................................................... 4
Step 1: ......................................................................................................................................................................... 4
Step 2: ......................................................................................................................................................................... 4
Step 3: ......................................................................................................................................................................... 4
Step 4: ......................................................................................................................................................................... 4
Step 5: ......................................................................................................................................................................... 5
Appendix A. How to use the Program ................................................................................................................ 6
Appendix B. Three additional infoObjects just for screen programming ............................................................ 8
Appendix C. Additional Match Code for Screen Programming ........................................................................ 11
Appendix D. Create InfoPackage which to be called by ZHIERLOAD ............................................................. 14
Appendix E. ZHIERLOAD Source Code ........................................................................................................... 17
Related Content ................................................................................................................................................ 20
Disclaimer and Liability Notice .......................................................................................................................... 21

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 2
How to Automate Loading Hierarchies from R3 / ECC

Purpose
ZHIERLOAD is an ABAP Program created using SE38. The purpose of this program is to automate loading
hierarchies.

Case Study / Scenario sample


Take example for InfoObject
This infoobject has hierarchy datasource 0ACCOUNT_0109_HIER and the sample infopackage
ZPAK_D9PE2ODPBQHZ9GEDJQTRUGGAA as picture below.

If we have 4 hierarchies like below, then we need to run this Infopackage one-by-one.

Solution
We will develop an ABAP program, and create some customized InfoPackage. It has 4 core components as
follow:

1: Using Standard SAP Function Module


BW has standard function module (FM) to call list of hierarchies available for an infoObject / datasource.
The name is: RSAP_REMOTE_HIERARCHY_CATALOG

The list of Hierarchies will be in l_t_hiers standard table

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 3
How to Automate Loading Hierarchies from R3 / ECC

2: Creating Custom infoPackage with Embedded ABAP Code


We have to create a new infoPackage: Load Hierarchy from ABAP. The specs and detail are below.

3: Call above Infopackage using BAPI Standard Function Module. BAPI_IPAK_START

4: Utilize TVARV Table


How to facilitate communication from l_t_hiers to infopackage, we have to perform the following 2 steps:

Step 1:
We reuse a SAP standard table for our purpose. The table is TVARV

We need to insert a value ZHIERLOAD as variable name as above.

Step 2:
We need to modify infopackage Load Hierarchy from ABAP (ZPAK_DA4ZAZIXQAWFVUZQ0F4HESSC2) as
follow

Step 3:
Use ABAP on Dynamic hierarchy Selection

Step 4:
Choose Determine Using Routine

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 4
How to Automate Loading Hierarchies from R3 / ECC

Step 5:
In the routine just type as follow.

The whole ZHIERLOAD source code is in appendix E.


How to use ZHIERLOAD is in appendix A.

Appendix B and Appendix C are basically just for the sake of the screen programming and user interface
sake. The core engine and logic is summarized above.

Appendix D is a reference how to create a typical infopackage, which will be called by ZHIERLOAD .

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 5
How to Automate Loading Hierarchies from R3 / ECC

Appendix A. How to use the Program


1. Open SE38 - ZHIERLOAD

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 6
How to Automate Loading Hierarchies from R3 / ECC

2. Execute (Press F8) and screen will be like follow

Choose if you want to load the data. If you dont check, the program will skip the
hierarchy.
In our sample we want to load 0ACCOUNT Hierarchy with infopackage Load Hierarchy from ABAP
(ZPAK_DA4ZAZIXQAWFVUZQ0F4HESSC2). The source system is IDECLNT800 source system. Therefore
the screen should look like below:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 7
How to Automate Loading Hierarchies from R3 / ECC

Appendix B. Three additional infoObjects just for screen programming


These types:

Above types are infoObjects, and they are created for the sake of screen programming. You can create
above types by creating those InfoObjects as follow:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 8
How to Automate Loading Hierarchies from R3 / ECC

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 9
How to Automate Loading Hierarchies from R3 / ECC

The master data / text configuration are identical for three of them. For the sake of simplicity, I just print
screen ZSK_HIER

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 10
How to Automate Loading Hierarchies from R3 / ECC

Appendix C. Additional Match Code for Screen Programming


To enable user to choose InfoPackage from a BI source system, I created a search help (match code) for
Info Package. The name is ZIPAK_LIST

Its based on a database view called by the same name, ZIPAK_LIST. ZIPAK_LIST View is based on
InfoPackage table: RSLDPIO and RSLDPIOT

This is the ABAP parameters in ZHIERLOAD

Here are the setup for ZIPAK_LIST View:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 11
How to Automate Loading Hierarchies from R3 / ECC

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 12
How to Automate Loading Hierarchies from R3 / ECC

Here is the setup for the ZIPAK_LIST matchcode:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 13
How to Automate Loading Hierarchies from R3 / ECC

Appendix D. Create InfoPackage which to be called by ZHIERLOAD


You need to create an infoPackage, to be called by ZHIERLOAD. Steps are as follow:

You will see screen below:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 14
How to Automate Loading Hierarchies from R3 / ECC

Type sample 1, choose Hierarchies, Click save and you will see something like following:

Choose Dynamic Hierarchy Selections, like below. Click it

Next, Choose determine using routine and click the new button:

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 15
How to Automate Loading Hierarchies from R3 / ECC

Click the editor, and you will have screen similar to below.

Replace above code With the one below.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 16
How to Automate Loading Hierarchies from R3 / ECC

Appendix E. ZHIERLOAD Source Code


*&---------------------------------------------------------------------*
*& Report ZHIERLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zhierload.

DATA:
l_t_hiers LIKE TABLE OF rshiertrsf,
l_s_hiers LIKE rshiertrsf,
it_return LIKE TABLE OF bapiret2,
l_pc_hier TYPE /bic/oizpc_hier,
l_ac_hier TYPE /bic/oizac_hier,
l_sk_hier TYPE /bic/oizsk_hier,
d_ucomm LIKE sy-ucomm,
l_t_myscreen TYPE TABLE OF screen WITH HEADER LINE.

CONSTANTS:
ds_ac TYPE c LENGTH 60 VALUE '0ACCOUNT_0109_HIER',
ds_pc TYPE c LENGTH 60 VALUE '0PROFIT_CTR_0106_HIER',
ds_sk TYPE c LENGTH 60 VALUE '0STKEYFIG_0104_HIER'.

PARAMETERS: p_logsys type c length 11.


SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME TITLE text-001.


PARAMETERS p_ac0010 TYPE c AS CHECKBOX USER-COMMAND p_ac0010.
PARAMETERS p_ac0030 TYPE rslogdpid MATCHCODE OBJECT zipak_list MODIF ID a01.
SELECT-OPTIONS p_ac0020 FOR l_ac_hier MODIF ID a01.
SELECTION-SCREEN END OF BLOCK blk01.

SELECTION-SCREEN BEGIN OF BLOCK blk02 WITH FRAME TITLE text-002.


PARAMETERS p_pc0010 TYPE c AS CHECKBOX USER-COMMAND p_pc0010.
PARAMETERS p_pc0030 TYPE rslogdpid MATCHCODE OBJECT zipak_list MODIF ID b01.
SELECT-OPTIONS p_pc0020 FOR l_pc_hier MODIF ID b01.
SELECTION-SCREEN END OF BLOCK blk02.

SELECTION-SCREEN BEGIN OF BLOCK blk03 WITH FRAME TITLE text-003.


PARAMETERS p_sk0010 TYPE c AS CHECKBOX USER-COMMAND p_sk0010.
PARAMETERS p_sk0030 TYPE rslogdpid MATCHCODE OBJECT zipak_list MODIF ID c01.
SELECT-OPTIONS p_sk0020 FOR l_sk_hier MODIF ID c01.
SELECTION-SCREEN END OF BLOCK blk03.

AT SELECTION-SCREEN.
d_ucomm = sy-ucomm.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.
IF p_ac0010 = ' ' AND screen-group1 = 'A01'.
screen-input = 0.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 17
How to Automate Loading Hierarchies from R3 / ECC

p_ac0030 = ''.
ENDIF.
IF p_ac0010 = 'X' AND screen-group1 = 'A01' AND screen-name = 'P_AC0030'.
screen-required = 1.
ENDIF.

IF p_pc0010 = ' ' AND screen-group1 = 'B01'.


screen-input = 0.
p_pc0030 = ''.
ENDIF.
IF p_pc0010 = 'X' AND screen-group1 = 'B01' AND screen-name = 'P_PC0030'.
screen-required = 1.
ENDIF.

IF p_sk0010 = ' ' AND screen-group1 = 'C01'.


screen-input = 0.
p_sk0030 = ''.
ENDIF.
IF p_sk0010 = 'X' AND screen-group1 = 'C01' AND screen-name = 'P_SK0030'.
screen-required = 1.
ENDIF.

MODIFY SCREEN.
ENDLOOP.

** Store screen condition as internal table so


** we avoid multiple calling to same statements.
CLEAR l_t_myscreen.
LOOP AT SCREEN.
MOVE-CORRESPONDING screen TO l_t_myscreen.
APPEND l_t_myscreen.
SORT l_t_myscreen ASCENDING.
DELETE ADJACENT DUPLICATES FROM l_t_myscreen comparing name.
ENDLOOP.

START-OF-SELECTION.

DATA: l_ds_variable TYPE c LENGTH 10,


l_chabasnm TYPE rohiebas-chabasnm,
l_infopackage TYPE bapi6109-infopackage,
l_process_this TYPE c LENGTH 1,
l_hier_name TYPE c LENGTH 10.

FIELD-SYMBOLS: <l_t_myscreen> LIKE LINE OF l_t_myscreen,


<l_myscreen_data> TYPE c,
<l_ds_variable> TYPE c,
<l_r_hierarchies> TYPE STANDARD TABLE.

LOOP AT l_t_myscreen ASSIGNING <l_t_myscreen> WHERE group3 EQ 'PAR' OR group3 EQ


'HGH'.
* As l_t_my_screen-name is a variable name, we need value, not the variable itself.
ASSIGN (<l_t_myscreen>-name) TO <l_myscreen_data>.

* The initial driver, sequence 0010


IF <l_t_myscreen>-name+4(4) = '0010'.
CLEAR: l_process_this, l_chabasnm, l_infopackage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 18
How to Automate Loading Hierarchies from R3 / ECC

IF <l_myscreen_data> EQ 'X'.
l_process_this = 'X'. "sequence 100 determine to process seq 20 and onwards
* find the datasource from l_t_my_screen-name
CONCATENATE 'DS_' <l_t_myscreen>-name+2(2) INTO l_ds_variable.
ASSIGN (l_ds_variable) TO <l_ds_variable>.
l_chabasnm = <l_ds_variable>.
ENDIF.
ENDIF.

* Sequence 0020, the hierarchy restriction


IF <l_t_myscreen>-name+4(4) = '0020' AND l_process_this = 'X'.
CONCATENATE <l_t_myscreen>-name(8) '[]' INTO l_hier_name.
ASSIGN (l_hier_name) TO <l_r_hierarchies>.
ENDIF.

* Sequence 0030, get infopackage name


IF <l_t_myscreen>-name+4(4) = '0030' AND l_process_this = 'X'.
l_infopackage = <l_myscreen_data>.
ENDIF.

* This is the actual engine after the last sequence.


IF l_infopackage IS NOT INITIAL.

*1. Populate all hierarchies


CLEAR: l_t_hiers.

CALL FUNCTION 'RSAP_REMOTE_HIERARCHY_CATALOG'


DESTINATION p_logsys
EXPORTING
i_chabasnm = l_chabasnm
i_langu = 'E'
TABLES
e_t_hiers = l_t_hiers.

*2. Clear some hierarchies according to 0020 rules


DELETE l_t_hiers WHERE hienm NOT IN <l_r_hierarchies>.

*3. Loop at hierarchies and call infopackage according to 0030 rules.


LOOP AT l_t_hiers INTO l_s_hiers.
UPDATE tvarv
SET low = l_s_hiers-hienm
WHERE name = 'ZHIERLOAD'.
CALL FUNCTION 'BAPI_IPAK_START'
EXPORTING
infopackage = l_infopackage
TABLES
return = it_return.
ENDLOOP.
ENDIF.
ENDLOOP.

LEAVE PROGRAM

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 19
How to Automate Loading Hierarchies from R3 / ECC

Related Content
NW70 Infopackage in detail
Defining Selection Screens (ABAP SE38)
Match code / ABAP Search Help
BAPI - In general
BAPI_IPAK_START - BAPI for infopackage
For more information, visit the EDW homepage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
2011 SAP AG 20
How to Automate Loading Hierarchies from R3 / ECC

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 | UAC - uac.sap.com
2011 SAP AG 21