Skip to Content

We have standard function module where the ABAP code retrieve the full BW hierarchy. Retrieving BW Hierarchy partially is always painful when we do not find the standard function module. This document will help you to create the ABAP program which will retrieve BW info object hierarchy fully or partially based on selected node.

Let me give you an example regarding 0GL_ACCOUNT info object. The hierarchy is maintained in 0GL_ACCOUNT. We will talk about the hierarchy name ‘XXXX’. (Please use Hierarchy Name – where you want to retrieve information)

Suppose we want to retrieve the hierarchy leaves information for node XXXX56.

>> We created a program in se38 t-code.

>> If we run the program, the below i/p screen will appear for user input. We have to provide Hierarchy name and Node Name.

>> The output will be below.

>> Please include below code in se38 screen.

PARAMETERS : p_node TYPE rsshnodenamestr DEFAULT ‘XXXX25’,
p_hinm       TYPE rshienm DEFAULT ‘XXXX’.

DATA: lw_hier_id TYPE rshi_s_rshiedirkey.
DATA: lt_nodes_a_leaves TYPE rshi_t_hienode,
lt_nodes_a_leaves_final TYPE rshi_t_hienode,
lt_nodes_a_leaves_parent TYPE rshi_t_hienode,
lt_nodes_a_leaves_temp TYPE rshi_t_hienode,
wa_leaves TYPE rshi_s_hienode.
DATA: lw_nodes_a_leaves LIKE LINE OF lt_nodes_a_leaves.

DATA: l_hier_name TYPE rshienm.
DATA: lw_hier_type TYPE rshiedir.

TYPES : BEGIN OF ty_counter ,
nodeid TYPE rshienodid,
parentid TYPE rshienodid,
childid TYPE rschild,
END OF ty_counter,

ty_t_counter TYPE TABLE OF  ty_counter.

DATA : it_counter TYPE ty_t_counter,
wa_counter TYPE ty_counter,
wa_counter1 TYPE ty_counter.

l_hier_name = p_hinm.

SELECT SINGLE * FROM rshiedir INTO lw_hier_type
WHERE hienm = l_hier_name
AND objvers = ‘A’.

IF sy-subrc = 0.
lw_hier_id-hieid = lw_hier_type-hieid.
lw_hier_id-objvers = ‘A’.

CALL FUNCTION ‘RSSH_HIERARCHY_READ’
EXPORTING
i_rshiedirkey           = lw_hier_id
IMPORTING
e_t_rsnodes             = lt_nodes_a_leaves
EXCEPTIONS
invalid_hierarchy       = 1
name_error              = 2
iobj_not_found          = 3
OTHERS                  = 4
.
IF sy-subrc <> 0.

ENDIF.

ENDIF.

READ TABLE lt_nodes_a_leaves INTO wa_leaves WITH KEY nodename = p_node.
IF sy-subrc IS INITIAL.
wa_counter-parentid = wa_leaves-nodeid.
APPEND:  wa_leaves TO lt_nodes_a_leaves_final ,
wa_counter TO it_counter.
ENDIF.

CLEAR : wa_counter,
wa_counter1.

LOOP AT it_counter INTO wa_counter .
CLEAR wa_leaves.
LOOP AT lt_nodes_a_leaves INTO wa_leaves WHERE parentid = wa_counter-parentid.
wa_counter1-parentid = wa_leaves-nodeid.

APPEND:  wa_leaves TO lt_nodes_a_leaves_final,
wa_counter1 TO it_counter.

CLEAR wa_leaves.
ENDLOOP.
CLEAR wa_counter.
ENDLOOP.

*
DELETE lt_nodes_a_leaves_final WHERE iobjnm = ‘0HIER_NODE’.

CLEAR wa_leaves.
LOOP AT lt_nodes_a_leaves_final INTO wa_leaves.
WRITE: /  wa_leaves-nodename.
ENDLOOP.

 

>> To retrieve Full hierarchy we have to include below code.

PARAMETERS : p_node TYPE rsshnodenamestr DEFAULT ‘MAGM25’,
p_hinm       TYPE rshienm DEFAULT ‘MAGM’.

DATA: lw_hier_id TYPE rshi_s_rshiedirkey.
DATA: lt_nodes_a_leaves TYPE rshi_t_hienode,
lt_nodes_a_leaves_final TYPE rshi_t_hienode,
lt_nodes_a_leaves_parent TYPE rshi_t_hienode,
lt_nodes_a_leaves_temp TYPE rshi_t_hienode,
wa_leaves TYPE rshi_s_hienode.
DATA: lw_nodes_a_leaves LIKE LINE OF lt_nodes_a_leaves.

DATA: l_hier_name TYPE rshienm.
DATA: lw_hier_type TYPE rshiedir.

TYPES : BEGIN OF ty_counter ,
nodeid TYPE rshienodid,
parentid TYPE rshienodid,
childid TYPE rschild,
END OF ty_counter,

ty_t_counter TYPE TABLE OF  ty_counter.

DATA : it_counter TYPE ty_t_counter,
wa_counter TYPE ty_counter,
wa_counter1 TYPE ty_counter.

l_hier_name = p_hinm.

SELECT SINGLE * FROM rshiedir INTO lw_hier_type
WHERE hienm = l_hier_name
AND objvers = ‘A’.

IF sy-subrc = 0.
lw_hier_id-hieid = lw_hier_type-hieid.
lw_hier_id-objvers = ‘A’.

CALL FUNCTION ‘RSSH_HIERARCHY_READ’
EXPORTING
i_rshiedirkey           = lw_hier_id
IMPORTING
e_t_rsnodes             = lt_nodes_a_leaves
EXCEPTIONS
invalid_hierarchy       = 1
name_error              = 2
iobj_not_found          = 3
OTHERS                  = 4
.
IF sy-subrc <> 0.

ENDIF.

ENDIF.

>> The internal table lt_nodes_a_leaves contains full hierarchy data.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. Sajid Amir

      Shanthi, please use comments as you did here to get attention of the author. Please do not use “Alert Moderator” for such inquiries.

      (0) 
  1. Shanthi Bhaskar

    Was trying to loop in Moderator so that he would assist or guide the author in making blog/wiki more accurate with pictorial representation so that more people will read.

    (0) 

Leave a Reply