Skip to Content
Author's profile photo Former Member

Create hierarchy using any source

With the new 7.3 hierarchy framework, it is now possible to load a hierarchy from any datasource, be it a DSO, flat file or a non-hierarchy datasource.

In this post, I’ll walk through the process of loading a hierarchy from a master data attributes datasource. The hierarchy to be created consists of 5 levels and contains an external characteristic.

The Infoobject ZXCMDTYCD is enabled for hierarchy and an external characteristic (ZXCMDGRN) has been added for the hierarchy. The hierarchy will be a standard hierarchy and will not be time dependent.

The new BW framework consists of 5 target segments. More information can be found at –

Creating a Transformation for a Hierarchy – Modeling – SAP Library

Examples of a Hierarchy Transformation – Modeling – SAP Library

In the current example, there is no NODEID, PARENTID, CHILDID or NEXTID available. The data is a flat table with each CMDTY_CD assigned under up to 5 levels. This data needs to be converted into a proper format required for loading of hierarchy.

Source Data –
2-3-2014 8-47-56 AM.png

We start with creating a dummy hierarchy that we will use in the transformations.

2-3-2014 9-02-11 AM.png

Some of the parameters are hard coded within the transformations. In this example, the transformation is used to load only one hierarchy. Hence the hierarchy header information is constant. If you want to load multiple hierarchies, you can modify them through your source data or code it in your end routine.

2-3-2014 9-05-54 AM.png
2-3-2014 9-06-14 AM.png

The challenge is to populate the hierarchy structure with the proper node, parent, child and next ID’s.

We start by finding the parent nodes at each level and storing them in individual tables. The parent nodes for lowers levels will be children for upper nodes. We will take that into consideration when we populate the parent and child ID. In this example, all the ‘parent’ nodes are external characteristics. Their children might be CMDTY_CD or lower group level code.

2-3-2014 9-50-51 AM.png

The parent nodes for the top most level are populated.

2-3-2014 10-26-58 AM.png

We then add level 2 objects to the hierarchy. We make one pass for all the external characteristics and then another for all the CMDTY_CD that might be present. For finding the CMDTY_CD, we do a search within the entire table and not on the individual levels.

2-3-2014 10-40-04 AM.png
2-3-2014 10-40-34 AM.png

We repeat the process for all 5 levels. Since level 5 will not have any children from the external characteristic, we only look for CMDTY_CD for that level.

The code can be modified to fit a hierarchy with no external characteristic or with different number of levels. The link node would be needed if you have the same object used multiple times in the hierarchy.

The next step is to create a DTP for loading the hierarchy. We will use a full load info package to load data into PSA and then subsequently into the hierarchy.

2-3-2014 10-42-22 AM.png

2-3-2014 10-42-36 AM.png

You can see the hierarchy loaded once the DTP is run –

2-3-2014 10-47-10 AM.png

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Sameer,

      Great post.

      I have few questions:

      1 - Where do i write the code? (start routine, end routine..)?

      2 - The numbers of levels is not constant at my hierarchy ( 5 in your example). Is it a problem?

      Best regards,


      Author's profile photo Former Member
      Former Member

      Hi Sameer

      Will it be possible to have the entire code, including the declaration part, in a downloadable format instead as a picture?

      Author's profile photo Former Member
      Former Member

      Hi Hi  Former Member ,

      Can you share a downloadable  file with the abap code with more details on how to use the code? It would be more usefully for people with less abap knowledge .



      Author's profile photo Former Member
      Former Member

      Hi Sameer,

      This is a very detailed and useful document. Thanks for your effort and energy in updating the SAP  BI community with yoúr Knowledge in the field. However, there is a piece that is missing in this document - and that is the code declartion part -. I have tried your approach and possibly imagining some inputs to make your code adaptable for my purpose but it does not work.

      E: "it_favssh" ist not an internal table. In your example it is: "it_cmdcode"

      I know some guys have already requested you to post this part. It is most obvious that you would be very busy on your project, however, it 'ld be nice and a complete piece of work to find a little time to post the complete code including how you did the declaration.

      Thanks so much for your attention


      Author's profile photo Galland Peng
      Galland Peng

      Awesome document!!! But code for variable declaration is missing, complete code will be highly appreciated.