Sometimes we may need to generate hierarchies manually, in that case if you know Node id and it’s Parent ID then we can generate hierarchies successfully. you can also add root node if our requirement demands. Please check below for the details :
Source : Any source with fields Node Id and Parent ID
Target : Info provider specific Info object with hierarchy option enabled.
Please check below for the hierarchy which is already loaded using Node ID and Parent ID
In the above generated hierarchy the node ALL is not coming from Source and we need this to be added to our hierarchy. Please check below code written in the BW Start Routine
DATA : WA_SOURCE_PACKAGE like LINE OF SOURCE_PACKAGE.
WA_SOURCE_PACKAGE–ID = ‘1’.
WA_SOURCE_PACKAGE–NAME = ‘ALL’.
APPEND WA_SOURCE_PACKAGE TO SOURCE_PACKAGE.
Note : Here assume CT_MGMT represents Parent Id for a management Hierarchy which is coming from source object.
In the above Start Routine code we have created a new record (node id) with parent as blank which represents Root Node ( ALL ).
In the above screen shot we have a Field Level Routine for 0H_PARENTID which maps all child nodes to its respective parent node.
Please check below for the ABAP code :
IF SOURCE_FIELDS–CT_MGMT is INITIAL AND SOURCE_FIELDS–ID NE ‘1’.
RESULT = SOURCE_FIELDS–CT_MGMT.