At first, I thought about starting my SDN blogging career with a stupid “hello world” post. But then I decided to write something (in my opinion) more valuable.
In several customer projects, I had the requirement to build non-standard SAP hierarchies based on SAP BW data. I had to generate special organization/customer hierarchies, date hierarchies and hierarchies based on 3th party data which are stored in DSOs. All these different hierarchies had to be created dynamically because of the base data being changed frequently (daily, monthly etc.).
SAP NetWeaver BW offers several possibilities to build hierarchies:
Wouldn’t it be great to have a comfortable hierarchy framework with simple functions like “create node”, “add node” or “add child” to easily build a hierarchy and not having to care about the complex ID assignment and flat file creation? I think it would.
What do we need? We need two objects:
Both objects take care of the ID assignment for PARENTID, CHILDID, and NEXTID and additionally assign each node to the correct level for a node. That sounds good.
There are two classes for the objects
UML class diagram
The hierarchy class ZCL_GENERIC_HIERARCHY is defined as an abstract class and cannot be instantiated. Common behaviour like ADD_NODE() is implemented in the abstract class while the BUILD_HIERARCHY() method, however, must be implemented in an inherited class with its own coding.
A coding example for a dynamic hierarchy on 0CALMONTH is described in the following post: example-for-a-generic-date-hierarchy-on-0calmonth