You are on page 1of 8

www.biportal.

org

BPC BW Hierarchy – Example 2

Table of Contents
BPC BW Hierarchy – Example 2 ...................................................................................................................... 1
Business Case ......................................................................................................................................... 1
BW Model for 0GL_Account InfoObject................................................................................................. 1
BPC Account InfoObject ZBACCOUNT ................................................................................................... 3

Business Case
In the Example 2 we generate master data for BPC Accounts based on GL Account hierarchy nodes (level
1 in the hierarchy is a BPC Account). After that we generate attributes, text and hierarchies for the BPC
accounts based on the corresponding GL Account hierarchies (BEGAAP and IFRS).

BW Model for 0GL_Account InfoObject

Page | 1
www.biportal.org

Attributes

TYPES:
BEGIN OF ty_ah,
NODEID TYPE RSHIENODID,
NODENAME TYPE RSSHNODENAME,
PARENTID TYPE RSPARENT,
END OF ty_ah.
DATA ah TYPE HASHED TABLE OF ty_ah WITH UNIQUE KEY NODEID.
FIELD-SYMBOLS: <ah> TYPE ty_ah, <ah1> TYPE ty_ah.
DATA hid TYPE RSHIEID.
DATA glac TYPE RSSHNODENAME.

TYPES:
BEGIN OF ty_aht,
LANGU TYPE LANGU,
NODENAME TYPE RSSHNODENAME,
TXTSH TYPE RSTXTSH,
TXTMD TYPE RSTXTMD,
TXTLG TYPE RSTXTLG,
END OF ty_aht.

DATA aht TYPE HASHED TABLE OF ty_aht WITH UNIQUE KEY NODENAME LANGU.
FIELD-SYMBOLS: <aht> TYPE ty_aht.

* Populate Mapping for BEGAAP


SELECT SINGLE HIEID FROM RSHIEDIR
INTO hid
WHERE IOBJNM = '0GL_ACCOUNT' AND HIENM = 'BEGAAP'.

SELECT * FROM /BI0/HGL_ACCOUNT


INTO CORRESPONDING FIELDS OF TABLE ah
WHERE HIEID = hid.

SELECT * FROM RSTHIERNODE


INTO CORRESPONDING FIELDS OF TABLE aht
WHERE HIEID = hid AND OBJVERS = 'A'.

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.


CONCATENATE 'BHLU' <RESULT_FIELDS>-GL_ACCOUNT INTO glac.
READ TABLE ah ASSIGNING <ah>
WITH KEY NODENAME = glac.
IF sy-subrc = 0.
READ TABLE ah ASSIGNING <ah1>
WITH TABLE KEY NODEID = <ah>-PARENTID.
IF sy-subrc = 0.
* Add English text
READ TABLE aht ASSIGNING <aht>

Page | 2
www.biportal.org

WITH TABLE KEY NODENAME = <ah1>-NODENAME


LANGU = 'EN'.
IF sy-subrc = 0.
<RESULT_FIELDS>-/BIC/ZBPCACCIF = <aht>-TXTMD(6).
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.

BPC Account InfoObject ZBACCOUNT

Page | 3
www.biportal.org

Attributes

ZBACCOUNT:
IF SOURCE_FIELDS-/BIC/ZBPCACC <> ' '.
RESULT = SOURCE_FIELDS-/BIC/ZBPCACC.
ELSE.
RESULT = SOURCE_FIELDS-/BIC/ZBPCACCIF.
ENDIF.

Hierarchy
* T1 ------------------
DATA: rp1 TYPE _ty_s_TG_1.
rp1-H_HIENM = 'IFRS'.
rp1-H_STARTLEV = '1'.
INSERT rp1 INTO TABLE RESULT_PACKAGE_1.

* T3 and T4 ------------------ Prepare Hierarchy Text


DATA: rp4 TYPE _ty_s_TG_4.
TYPES:
BEGIN OF ty_aht,
LANGU TYPE LANGU,
NODENAME TYPE RSSHNODENAME,
TXTSH TYPE RSTXTSH,
TXTMD TYPE RSTXTMD,
TXTLG TYPE RSTXTLG,
END OF ty_aht.

Page | 4
www.biportal.org

FIELD-SYMBOLS: <RESULT_FIELDS> TYPE _ty_s_TG_3.


DATA hid TYPE RSHIEID.
* Retrieve Hierarchy for BEGAAP
SELECT SINGLE HIEID FROM RSHIEDIR INTO hid
WHERE IOBJNM = '0GL_ACCOUNT' AND HIENM = 'BEGAAP'.

DATA aht TYPE HASHED TABLE OF ty_aht WITH UNIQUE KEY NODENAME LANGU.
FIELD-SYMBOLS: <aht> TYPE ty_aht.

SELECT * FROM RSTHIERNODE


INTO CORRESPONDING FIELDS OF TABLE aht
WHERE HIEID = hid AND OBJVERS = 'A'.

* T3 ------------------ Hierarchy Structure


TYPES:
BEGIN OF ty_ah,
NODEID TYPE RSHIENODID,
NODENAME TYPE RSSHNODENAME,
NEWNAME TYPE C LENGTH 60,
PARENTID TYPE RSPARENT,
END OF ty_ah.

DATA ah TYPE STANDARD TABLE OF ty_ah.


FIELD-SYMBOLS: <ah> TYPE ty_ah, <ah1> TYPE ty_ah.

SELECT * FROM /BI0/HGL_ACCOUNT


INTO CORRESPONDING FIELDS OF TABLE ah
WHERE HIEID = hid AND OBJVERS = 'A'.

DATA: nid TYPE N LENGTH 8.


DATA: rp TYPE _ty_s_TG_3.
FIELD-SYMBOLS: <rp> TYPE _ty_s_TG_3.

* generate lines for lowest level


nid = 1.
rp-H_IOBJNM = 'ZBACCOUNT'.
LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.
rp-H_NODEID = nid.
nid = nid + 1.
rp-H_HIERNODE = rp-/BIC/ZBACCOUNT = <SOURCE_FIELDS>-/BIC/ZBACCOUNT.
INSERT rp INTO TABLE RESULT_PACKAGE_3.
ENDLOOP.

* Retrieve Node ID from text


LOOP AT ah ASSIGNING <ah>.
<ah>-NEWNAME = <ah>-NODENAME.
READ TABLE aht ASSIGNING <aht>

Page | 5
www.biportal.org

WITH TABLE KEY NODENAME = <ah>-NODENAME


LANGU = 'EN'.
IF sy-subrc = 0.
READ TABLE SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>
WITH KEY /BIC/ZBACCOUNT = <aht>-TXTMD(6).
IF sy-subrc = 0.
<ah>-NEWNAME = <aht>-TXTMD(6).
ENDIF.
ENDIF.
ENDLOOP.

* assign parent node ids


rp-H_IOBJNM = '0HIER_NODE'.
LOOP AT RESULT_PACKAGE_3 ASSIGNING <RESULT_FIELDS>.
READ TABLE ah ASSIGNING <ah>
WITH KEY NEWNAME = <RESULT_FIELDS>-/BIC/ZBACCOUNT.
IF sy-subrc = 0.
* Check for parent in Source Hierarchy
READ TABLE ah ASSIGNING <ah1>
WITH KEY NODEID = <ah>-PARENTID.
IF sy-subrc = 0.
READ TABLE RESULT_PACKAGE_3 ASSIGNING <rp>
WITH KEY /BIC/ZBACCOUNT = <ah1>-NODENAME
H_IOBJNM = '0HIER_NODE'.
IF sy-subrc = 0.
<RESULT_FIELDS>-H_PARENTID = <rp>-H_NODEID.
ELSE.
* Add upper node to Result Package
rp-H_NODEID = nid.
nid = nid + 1.
rp-H_HIERNODE = rp-/BIC/ZBACCOUNT = <ah1>-NODENAME.
INSERT rp INTO TABLE RESULT_PACKAGE_3.
<RESULT_FIELDS>-H_PARENTID = rp-H_NODEID.
ENDIF.
ELSE.
* No parent found. Go next.
ENDIF.
ENDIF.
ENDLOOP.

SORT RESULT_PACKAGE_3 BY H_NODEID /BIC/ZBACCOUNT ASCENDING.


DELETE ADJACENT DUPLICATES FROM RESULT_PACKAGE_3 COMPARING H_NODEID.

* T4 ---------------------------- Populate Hierarchy text

LOOP AT RESULT_PACKAGE_3 ASSIGNING <RESULT_FIELDS> WHERE H_IOBJNM =


'0HIER_NODE'.
* Add English text

Page | 6
www.biportal.org

READ TABLE aht ASSIGNING <aht>


WITH TABLE KEY NODENAME = <RESULT_FIELDS>-H_HIERNODE
LANGU = 'EN'.
IF sy-subrc = 0.
rp4-H_HIERNODE = <RESULT_FIELDS>-H_HIERNODE.
rp4-LANGU = <aht>-LANGU.
rp4-TXTSH = <aht>-TXTSH.
rp4-TXTMD = <aht>-TXTMD.
rp4-TXTLG = <aht>-TXTLG.
INSERT rp4 INTO TABLE RESULT_PACKAGE_4.
ENDIF.
ENDLOOP.

Text

TYPES:
BEGIN OF ty_ah,
NODEID TYPE RSHIENODID,
NODENAME TYPE RSSHNODENAME,
PARENTID TYPE RSPARENT,
END OF ty_ah.
DATA ah TYPE HASHED TABLE OF ty_ah WITH UNIQUE KEY NODEID.
FIELD-SYMBOLS: <ah> TYPE ty_ah, <ah1> TYPE ty_ah.
DATA hid TYPE RSHIEID.
DATA glac TYPE RSSHNODENAME.

TYPES:

Page | 7
www.biportal.org

BEGIN OF ty_aht,
LANGU TYPE LANGU,
NODENAME TYPE RSSHNODENAME,
TXTSH TYPE RSTXTSH,
TXTMD TYPE RSTXTMD,
TXTLG TYPE RSTXTLG,
ba TYPE /BIC/OIZBACCOUNT,
END OF ty_aht.

DATA aht TYPE STANDARD TABLE OF ty_aht.


FIELD-SYMBOLS: <aht> TYPE ty_aht.

* Populate Mapping for BEGAAP


SELECT SINGLE HIEID FROM RSHIEDIR
INTO hid
WHERE IOBJNM = '0GL_ACCOUNT' AND HIENM = 'BEGAAP'.

SELECT * FROM RSTHIERNODE


INTO CORRESPONDING FIELDS OF TABLE aht
WHERE HIEID = hid AND OBJVERS = 'A' AND LANGU = 'EN'.

* Assign BPC Account from text


LOOP AT aht ASSIGNING <aht>.
<aht>-ba = <aht>-TXTMD(6).
ENDLOOP.

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.


* Add English text
READ TABLE aht ASSIGNING <aht>
WITH KEY ba = <RESULT_FIELDS>-/BIC/ZBACCOUNT.
IF sy-subrc = 0.
<RESULT_FIELDS>-LANGU = <aht>-LANGU.
<RESULT_FIELDS>-TXTSH = <aht>-TXTMD+9(20).
<RESULT_FIELDS>-TXTMD = <aht>-TXTLG+9(40).
<RESULT_FIELDS>-TXTLG = <aht>-TXTLG+9(50).
ENDIF.
ENDLOOP.

Contact us for help with SAP BW and BPC


Sergei Peleshuk has over 15 years of experience implementing BI technologies for
global clients in retail, distribution, fast-moving consumer goods (FMCG), oil, and
gas industries. He has helped clients to design robust BI reporting and planning
capabilities, leading them through all project phases: from analysis of requirements
to building BI roadmaps, technical architecture, and efficient BI teams. Sergei is an
expert in SAP Business Warehouse (SAP BW), SAP HANA, BPC, BusinessObjects, BO
Cloud, and SAP Lumira. You may contact Sergei at peleshuk@biportal.org

Page | 8