You are on page 1of 17

Architecture for Extracting the

Custom Hierarchies from SAP R/3


System into BW System

Applies to
SAP R/3, SAP BIW 3.5, SAP NetWeaver 7.0
For more information, visit the Business Intelligence homepage.

Summary
This document talks about the architecture that we can use for extracting the custom hierarchy, which is
maintained in custom table or in standard SAP tables for which no data source is provided by SAP as part of
business content.

Author: Nilesh Ramesh Ahir


Company: IBM India
Created on: 15 August 2009

Author Bio
Nilesh Ahir has completed his masters in Software System from BITS Pilani. He has total 4
years of SAP experience. He has been working as SAP NW BI Application consultant for
IBM India for last one year. Prior to this he was working with Intel India. He has experience in
ABAP, BW3.5 / BI7.0 and Data mining. He has worked on other non–SAP technologies like
TIBCO and web services.

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


© 2009 SAP AG 1
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Table of Contents

Introduction ......................................................................................................................................................... 3 
Business Scenario .............................................................................................................................................. 4 
Alternatives Available ...................................................................................................................................... 5 
Problem with Existing SAP Functionality ........................................................................................................ 5 
Existing File Based Architecture Used for Loading Custom Hierarchy .............................................................. 5 
Disadvantages of Using File Based Architecture ............................................................................................ 6 
Proposed Architecture ........................................................................................................................................ 6 
Advantages of New Proposed Architecture .................................................................................................... 6 
Detailed Architecture ....................................................................................................................................... 7 
Explanation of Detailed Architecture ............................................................................................................... 8 
Step by Step Implementation Guide ............................................................................................................... 8 
Limitations ....................................................................................................................................................... 9 
Related Content ................................................................................................................................................ 10 
Appendix ........................................................................................................................................................... 11 
Disclaimer and Liability Notice .......................................................................................................................... 17 

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


© 2009 SAP AG 2
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Introduction
Hierarchies are the parent child relationship between different things. In layman terminology - a series of
ordered groupings of people or things within a system.
We have hierarchies in SAP R/3 system maintained in Standard SAP tables and for them data sources are
provided by SAP as part of business content. These hierarchies are called as SAP Standard Hierarchies.
Where as we can have our own hierarchies which may or may not stored in Standard SAP tables, these are
called as Custom Hierarchies.

Root Node
World
Level 1

Asia America Australia Europe Continents


Level 2

India Pakistan China Country


Level 3

Maharashtra Karnataka Gujrath State


Level 4

Mumbai Pune Nagpur City


Level 5

Geo Hierarchy

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


© 2009 SAP AG 3
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Business Scenario
We want to extract custom hierarchy, which is maintained in custom tables or in SAP standard tables for
which no data source is provided by SAP as part of business content.
For example: Commodity schema hierarchy - A Commodity Schema is the complete list of commodity codes
representing all commodities which an Organization uses for indirect materials like stationary items, laptops
etc.
This is a custom hierarchy and every organization has its own hierarchy
chy structure.

Commodity
Schema root
node

Commodity Commodity Commodity


Schema Schema Schema
Super group 1 Super group 2 Super group 3

Group1 Group2 Group1 Group2 Group1 Group2

Stationary
Laptops
items

Cafeteria Other
items eg electronic
paper cups good

Commodity Schema Hierarchy – Custom Hierarchy

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


© 2009 SAP AG 4
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Alternatives Available
SAP BW/BI will allow you to load hierarchy by following two ways –
1. By using standard SAP data source – as there is no standard data source provided by SAP for our
custom hierarchy, this option is no more feasible.
2. By using file interface – this is the only alternative available with us to load custom hierarchies. But
this involve lots of complexity, dependencies and it is time consuming.

Problem with Existing SAP Functionality


SAP provide data sources for extracting the standard hierachies from SAP R/3 system into SAP BW/BI
system. SAP provide a tool (Transaction RSO2) for extracting data (master data – attributes and text) which
is maintained in custom tables or standard SAP tables but for which no data source has been provided.
Therefore we can see that there is no way we can create generic data source for the custom hierarchies in
R/3 system.

Existing File Based Architecture Used for Loading Custom Hierarchy


Following architecture is generally used for loading custom hierarchies from SAP R/3 system to SAP BW/BI
• Program to generating the flat file capturing hierarchy details as per SAP BW / BI format will be
executed
• This program will generate the file and save it on Application server. This file is then uploaded to
SAP BW/BI system through File interface.
• This process can be automated through process chains.

SAP BW/ BI
SAP R/3 Application DS System
System Server

Program for File


generating the Data
file Source

Landscape for loading the custom hierarchies using flat file interface

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


© 2009 SAP AG 5
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Disadvantages of Using File Based Architecture


1. It requires lot of development and testing efforts and time.
2. Difficult to do end to end monitoring
3. Need file management at Application server level
4. Time consuming – ETTL requires more time

Proposed Architecture
Following is the proposed architecture for loading custom hierarchies.
As per the architecture, we will create a generic data source for the custom hierarchy that will behave similar
to standard SAP hierarchy data source. We will use this generic data source for extracting the custom
hierarchy using standard data staging ETTL process.

SAP BW/ BI
SAP R/3 System
System DS

Generic Data Source


for custom hierarchy

Landscape for loading the custom hierarchies using generic data source

Advantages of New Proposed Architecture


1. It will require less development and testing efforts and time.
2. End to end monitoring will be much easier
3. No intermediate file generation there for less complexity and chances of failure is low
4. Less time consuming – ETTL requires less time

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


© 2009 SAP AG 6
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Detailed Architecture

Data Source for extracting the


ZDS_TEST custom Hierarchy

FM : ZFM_HIER_WRAPPER

FG :
ZBW_CUSTOM_HI
ERARCHY
FORM : EXTRACT_HIER

YCUSTOM_
HIER
Decision for which FM to
call
SAP R/3
System

ZFM_DS_TEST FM 2 FM 3

SAP / Custom
DataBase
Tables holding
Hierarchy
Inforamtion

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


© 2009 SAP AG 7
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Explanation of Detailed Architecture


This detailed architecture basically talks about how generic data source for custom hierarchy will work in
SAP R/3 system.
• When we will execute the info package for loading custom hierarchy from SAP R/3 system, BW/BI
system will send the request to SAP R/3 system that will trigger the Generic data source (e.g.
ZDS_TEST).
• Generic data source for custom hierarchy (ZDS_TEST) is based on Function module
ZFM_HIER_WRAPPER that is a common function module for all custom hierarchy data sources.
This function module will be called passing the name of hierarchy and other details to it.
• This function module will call a form EXTRACT_HIER that will fetch the hierarchy header text and
custom hierarchy specific extractor/function module (ZFM_DS_TEST) from custom table
YCUSTOM_HIER.
• Custom hierarchy specific extractor/function module (ZFM_DS_TEST) will extract the hierarchy and
populate internal table in BW/BI required format.
• Once hierarchy has been extracted and data is filled in internal tables the next part ie moving data
from R/3 to BW has taken care by SAP R/3 program for hierarchy data source.
• We can monitor this process of custom hierarchy extraction using standard SAP monitoring tool.

Note: Pass the name of Hierarchy while executing the info package and it should be same as that of data source for
custom hierarchy in SAP R/3

Step by Step Implementation Guide


Before creating the generic data source for custom hierarchy in R/3 system, create the building blocks or
dependent objects.
Following steps should be followed for the first time ie. For the first generic data source in R/3 system.
1. Create custom data base table YCUSTOM_HIER for holding the hierarchy header text and Function
module name that will actually extract the hierarchy data from underline data base tables. For the
table structure please see the Appendix 1.1
2. Create program for generating the generic data source for custom hierarchy. For pseudo code
please see the Appendix 1.2
3. Create Function Group for wrapper function module ZBW_CUSTOM_HIERARCHY
4. Create Wrapper function module - This will be the common Function Module for all Data Sources
that are created for extracting Custom Hierarchy. Create wrapper Function Module
ZFM_HIER_WRAPPER which will be the copy of standard Function Module
PHIE_HIERARCHY_TRANSFER . For pseudo code please check the Appendix 1.3
5. Write Form Extract_hier in top include of Function Group ZBW_CUSTOM_HIERARCHY. For
pseudo code please check the Appendix. 1.4
6. Create Function module specific to your custom hierarchy (ZFM_DS_TEST). For pseudo code
please check the appendix 1.5
7. Maintain table YCUSTOM_HIER with hierarchy details. For example please see the Appendix 1.1
8. Create generic data source using program created in step 2. for example please see the appendix
1.6
9. View the details of generic data source using transaction RSA2
10. Check generic data source for custom hierarchy using transaction RSA6.
11. Test you the data source using transaction RSA3. Give name of hierarchy to be extracted – it should
be same as that of data source.

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


© 2009 SAP AG 8
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

12. On success, replicate the data source to SAP BW system.


13. Assign data source
14. Create info package
15. Run the info package and monitor the load using standard monitoring tool
16. On success, check the hierarchy in BW system.

Note: For second data source for custom hierarchy follow the steps from 6 to 16.

Limitations
This architecture support only extraction of hierarchies that are not version dependent.

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


© 2009 SAP AG 9
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Related Content
SAP Library – BIW3.5 - Architecture
SAP Library – BIW3.5 - Hierarchies
SAP Library – BIW3.5 – Loading Hierarchies

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


© 2009 SAP AG 10
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Appendix
1.1 Structure of YCUSTOM_HIER table

Field Name Type In-built type length Description

Datasource ROOSOURCER char 30 Hierarchy name

Stext char 20 Short description


of Hierarchy

Mtext Char 40 Medium


Description

Ltext Char 60 Long Description

Func_module Char 30 Name of


Function Module

Maintained this table for custom hierarchies

Note: Name of Data source should same as name of custom hierarchy. At extraction level in selection screen we have to
mention the name of Hierarchy which is mandatory.

Also maintain the FM name that will be used for extracting the custom hierarchy.

e.g.

Datasource Stext Mtext Ltext Func_module

ZDS_TEST Commodity Commodity Commodity ZFM_DS_TEST


Schema Schema hierarchy Schema hierarchy

1.2 Pseudo code for program for generating the generic data source for custom hierarchy.
Use following pseudo code for generating the DS for Custom Hier

*&---------------------------------------------------------------------*
*& Report ZBW_CREATE_CUST_HIER_DS
*&
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZBW_CREATE_CUST_HIER_DS.
tables :
roohiecat,
roohiecom,
rodchabas,

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


© 2009 SAP AG 11
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

roosfield,
roosource,
roosourcet,
roosseg,
rohiebas.

data : t_rodchabas like table of rodchabas with header line,


t_roosource like table of roosource with header line,
t_roosourcet like table of roosourcet with header line,
t_roosfield like table of roosfield with header line,
t_roohiecom like table of roohiecom with header line,
t_roohiecat like table of roohiecat with header line,
t_roosseg like table of roosseg with header line,
t_rohiebas like table of rohiebas with header line.

parameters : p_iobj like rodcha-CHABASNM, "BW InfoObject


p_dsrce like roosource-OLTPSOURCE, "Datasource name
p_domain like rodchabas-domanm , "Domain of basic characteristic
p_dtelnm like rodcha-dtelnm , " data element of basic characteristic
p_apco like roosource-applnm , " Application Component
p_text like roosourcet-txtsh . " Desc of Data source
P_update as checkbox, "Actually update ?

start-of-selection.

* Update of table rodchabas


move p_iobj to t_rodchabas-chabasnm.
move p_domain to t_rodchabas-domanm.
move 'X' to t_rodchabas-hietabfl.
append t_rodchabas.

* Update of table roosource


move p_dsrce to t_roosource-OLTPSOURCE.
move 'A' to t_roosource-objvers.
move 'HIER' to t_roosource-type.
move p_apco to t_roosource-applnm.
move p_iobj to t_roosource-basosource.
move 'F1' to t_roosource-EXMETHOD.
move 'ZFM_HIER_WRAPPER' to t_roosource-EXTRACTOR.

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


© 2009 SAP AG 12
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

move 'ROHIEROS' to t_roosource-EXSTRUCT.


move SY-UNAME to t_roosource-TSTPNM.
move sy-datum to t_roosource-TSTPDAT.
move sy-uzeit to t_roosource-TSTPTIM.
move '1' to t_roosource-tfmethods.
append t_roosource.

* Update of table roosourcet


move p_dsrce to t_roosourcet-OLTPSOURCE.
move 'A' to t_roosourcet-objvers.
move 'EN' to t_roosourcet-langu.
move p_text to : t_roosourcet-txtsh, t_roosourcet-txtmd, t_roosourcet-txtlg.
append t_roosourcet.

* Update of table roosfield


move p_dsrce to t_roosfield-OLTPSOURCE.
move 'A' to t_roosfield-objvers.
move 'OLTPSOURCE' to t_roosfield-field.
move 'Y' to t_roosfield-notexrel.
append t_roosfield.

* Update of table roohiecom


move p_dsrce to t_roohiecom-OLTPSOURCE.
move 'A' to t_roohiecom-objvers.
move p_iobj to : t_roohiecom-fieldnm, t_roohiecom-fieldcmp.
move '1' to t_roohiecom-posit.
move p_dtelnm to t_roohiecom-dtelnm.
append t_roohiecom.

* Update of table roohiecat


move p_dsrce to t_roohiecat-OLTPSOURCE.
move 'A' to t_roohiecat-objvers.
move 'CUST' to t_roohiecat-typehc. "Custom Hier
move p_domain to t_roohiecat-domanm.
move p_dtelnm to t_roohiecat-rollnm.
move 'X' to t_roohiecat-hietabfl.
move 'ROSHIERSEL' to t_roohiecat-STRUC_HDR.
move 'ROSHIETEXT' to t_roohiecat-STRUC_HDRT.
move 'ROSHIENODE' to t_roohiecat-STRUC_NODE.
move 'ROSFOLDERT' to t_roohiecat-STRUC_NODT.
move 'ROSHIEINTV' to t_roohiecat-STRUC_INTV.

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


© 2009 SAP AG 13
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

append t_roohiecat.

* Update of table roosseg


move p_dsrce to t_roosseg-OLTPSOURCE.
move 'A' to t_roosseg-objvers.
move '0001' to t_roosseg-SEGID.
move 'ROSHIERSEL' to t_roosseg-SEGSTRUCT.
append t_roosseg.
move '0002' to t_roosseg-SEGID.
move 'ROSHIETEXT' to t_roosseg-SEGSTRUCT.
append t_roosseg.
move '0003' to t_roosseg-SEGID.
move 'ROSHIENODE' to t_roosseg-SEGSTRUCT.
append t_roosseg.
move '0004' to t_roosseg-SEGID.
move 'ROSFOLDERT' to t_roosseg-SEGSTRUCT.
append t_roosseg.

* Update of table rohiebas


move p_iobj to t_rohiebas-chabasnm.
move 'CUST' to t_rohiebas-hclass.
move w_domain to t_rohiebas-DOMANM.
move w_dtelnm to t_rohiebas-ROLLNM.
move 'ZFM_HIER_WRAPPER' to t_rohiebas-FHTRANSFER.
append t_rohiebas.

check p_update eq 'X'.


*Update data base tables
insert rodchabas from table t_rodchabas.
insert roosource from table t_roosource.
INSERT roosourcet from table t_roosourcet.
insert roosfield from table t_roosfield.
insert ROOHIECOM from table T_ROOHIECOM.
insert roohiecat from table t_roohiecat.
insert roosseg from table t_roosseg.
insert rohiebas from table t_rohiebas.

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


© 2009 SAP AG 14
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

1.3 Pseudo code for wrapper function module ZFM_HIER_WRAPPER

Perform Extract_hier Tables E_T_HIETEXT


E_T_HIENODE
E_T_FOLDERT
USING I_S_HIEBAS
I_S_HIEFLAG
I_S_HIERSEL
Changing
SUBRC .

IF subrc = 0.
* Hierarchy not found
RAISE hierarchy_tab_not_found.
ENDIF.

1.4 Pseudo code for Form Extract_hier

Form Extract_hier TABLES pt_hietext STRUCTURE roshietext


pt_hienode STRUCTURE roshienode
pt_foldert STRUCTURE rosfoldert
USING value (i_hiersel) LIKE roshiersel
CHANGING pv_subrc LIKE sy-subrc.
*Read custom hier details / Header Text
clear : wa_hier .
select single * from YCUSTOM_HIER into wa_hier
where datasource = i_hiersel-hienm .

IF sy-subrc = 0 and not wa_hier- Func_module is initial.


CLEAR: lw_hietext.
lw_hietext-langu = c_en.
lw_hietext-txtsh = wa_hier -stext. " Short Description
lw_hietext-txtmd = wa_hier -mtext. " Medium Description
lw_hietext-txtlg = wa_hier -ltext. " Long Description
APPEND lw_hietext TO pt_hietext.
**extract custom hier
*Build logic to fill the hierarchy
*fill internal table pt_hienode & pt_foldert
Call function wa_hier- Func_module tables pt_hienode

pt_foldert .
Else .

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


© 2009 SAP AG 15
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

Pv_subrc = 1 .
ENDIF.
Endform.

1.5 Pseudo code for Function module specific to your custom hierarchy (ZFM_DS_TEST).

* Build custom logic in this function module and fill the internal tables passed
to it in required format.
* Fill internal tables e.g. pt_hienode & pt_foldert

1.6 Screen shot of program for creating generic data source for custom hierarchy

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


© 2009 SAP AG 16
Architecture for Extracting the Custom Hierarchies from SAP R/3 System into BW System

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


© 2009 SAP AG 17