Skip to Content
Technical Articles
Author's profile photo Lakshminarasimhan Narasimhamurthy

BW Hierarchy Nodes of all levels and their Node texts in the BW Report in a single row


In BW system many times we get requirement to show the hierarchy data along with their multiple levels and texts but without activating the hierarchy display,on a single line. This blog explains how using a program you can get the hierarchy levels and their texts for any hierarchy within the BW system.

Applies to



Custom program to read any hierarchy within the BW system and then spot their multiple levels/nodes and levels/nodes texts.

Author          : Lakshminarasimhan Narasimhamurthy

Created on   : 17/Oct/2023



We are having a cost center report, GL report and a cost element report. All these infoobjects have hierarchy but for few reports the hierarchy is not enabled in BEx/in SAC. But in the report user wants to see the information as given below.

Consider a cost center that is at level 4 in hierarchy, which means there are 3 nodes/levels above it.

report display structure must be as below to end user,

Cost center  “Node 3 text” “Node 2 Text” “Node 1 Text”.

This helps business to know this cost center corresponds to which part of the hierarchy. Please note that the hierarchy is not enabled at the infoobject level, but still users wants to know if it belongs to which part of the hierarchy.

To address this, I have created a custom program(zbw4_hierarchy_levels) that read the hierarchy in the BW system, then splits it and stores it by levels in the custom table zbw4_hierlvl_01.

zbw4_hierlvl_01 is a custom table created in the BW system, with columns

  • infoobject_name data type rshiedir-iobjnm
  • Hieararchy_name data type rshiedir-hienm
  • nodename data type char length 50
  • level_01 to level_15 type char length 60

I have enabled levels from 1 up to 15 which can be used, if in case there are more levels then these columns can be added to the table.

once this table is available and simple look up can be performed on the custom table to get the level and texts. Also you can create a CDS view on top of this table and load into an ADSO and use this ADSO for the lookup/adding them to existing composite provider/load from ADSO into respective master data and enable navigational attributes on master data to show data as a flat structure in report.

Program code


report zbw4_hierarchy_levels.

" Custom structure
types : begin of lty_hier,
nodeid type rshienodid,
iobjnm type rsiobjnm,
nodename type rsshnodenamestr,
tlevel type rstlevel,
parentid type rsparent,
end of lty_hier.

tables : rsdiobj, rshiedir.

" Hierarchy tables starts with /BIC/H
constants lv_hie type string value '/BIC/H'.

selection-screen begin of block b1.
  parameters : iobjnm type rshiedir-iobjnm obligatory.
  parameters : hienm type rshiedir-hienm obligatory. " select hierarchy 
selection-screen end of block b1.

data: lv_hiertab type tabname,
      gv_ref type ref to data,
      lv_parentid type rsparent,
      la_hierlvl type zbw4_hierlvl_01,
      lt_hierlvl type standard table of zbw4_hierlvl_01,
      lt_hiernode_text type standard table of rsthiernode,
      la_hiernode_text type                   rsthiernode.

field-symbols: <gfs_itab>  type standard table,
               <gfs_wa>    type lty_hier,
               <gfs_wa_01> type lty_hier.

concatenate lv_hie iobjnm into lv_hiertab.

" Dynamic selection
select single * from rshiedir into @data(la_rshiedir)
where iobjnm = @iobjnm and hienm = @hienm and objvers = 'A'.

create data gv_ref type table of lty_hier.
assign gv_ref->* to <gfs_itab>.

" Assign hierarchy data to <gfs_itab>
from (lv_hiertab) into table @<gfs_itab>
where hieid = @la_rshiedir-hieid and objvers = 'A'.

" hierarchy node texts
select * from rsthiernode into table lt_hiernode_text
hieid = la_rshiedir-hieid and
objvers = 'A' and
langu = 'E'.

loop at <gfs_itab> assigning <gfs_wa>.

" ignore if the iobjnm is 0HIER_NODE
if <gfs_wa>-iobjnm <> '0HIER_NODE'.
clear la_hierlvl.

la_hierlvl-iobjnm = <gfs_wa>-iobjnm.
la_hierlvl-hienm = hienm.
la_hierlvl-nodename = <gfs_wa>-nodename.

lv_parentid = <gfs_wa>-parentid.

" Until root node is reached
while lv_parentid > 0.

  read table <gfs_itab> assigning <gfs_wa_01> with key ('NODEID') = lv_parentid.

  lv_parentid = <gfs_wa_01>-parentid.

" 0HIER_NODE indicates that is the hierarchy node 
  if <gfs_wa_01>-iobjnm = '0HIER_NODE'.

"Read the node text
  read table lt_hiernode_text into la_hiernode_text with key nodename = <gfs_wa_01>-nodename.

  if sy-subrc = 0.

"Assignment based on levels
  case <gfs_wa_01>-tlevel.
  when 01. la_hierlvl-level_01 = la_hiernode_text-txtlg.
  when 02. la_hierlvl-level_02 = la_hiernode_text-txtlg.
  when 03. la_hierlvl-level_03 = la_hiernode_text-txtlg.
  when 04. la_hierlvl-level_04 = la_hiernode_text-txtlg.
  when 05. la_hierlvl-level_05 = la_hiernode_text-txtlg.
  when 06. la_hierlvl-level_06 = la_hiernode_text-txtlg.
  when 07. la_hierlvl-level_07 = la_hiernode_text-txtlg.
  when 08. la_hierlvl-level_08 = la_hiernode_text-txtlg.
  when 09. la_hierlvl-level_09 = la_hiernode_text-txtlg.
  when 10. la_hierlvl-level_10 = la_hiernode_text-txtlg.
  when 11. la_hierlvl-level_11 = la_hiernode_text-txtlg.
  when 12. la_hierlvl-level_12 = la_hiernode_text-txtlg.
  when 13. la_hierlvl-level_13 = la_hiernode_text-txtlg.
  when 14. la_hierlvl-level_14 = la_hiernode_text-txtlg.
  when 15. la_hierlvl-level_15 = la_hiernode_text-txtlg.




append la_hierlvl to lt_hierlvl.



" Delete before insert
delete from zbw4_hierlvl_01 where iobjnm = iobjnm and hienm = hienm.
insert zbw4_hierlvl_01 from table lt_hierlvl.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.