INTRODUCTION
STANDARD HIERARCHY
Definition:
Standard hierarchy is a tree hierarchy which is used to organize business processes of a controlling area. The highest node of a standard hierarchy is normally the first business process group. The groups created thereafter make of the remaining nodes of the standard hierarchy.
The standard hierarchy is assigned directly to the controlling area and has itself a set of business process groups assigned to it. This ensures that all business processes belonging to a controlling area are grouped together.
Example:
Sales Hierarchy
Required Tables/Views:
Output Columns:
As explained earlier, that the leaf node will either be a group node or cost center; or cost center will always be a leaf node. So, here these two columns will be combined into one, creating a calculated column, and doing the same for description.
Required Tables/Views:
Input Parameters:
Output Columns:
The maximum level here is 4, so the flattening here will be done till level 4. If the hierarchy goes beyond level 4, then further flattening will be required.
Join details:
Calculated columns:
Shown below is how the graphical view will look:
STANDARD HIERARCHY
Definition:
Standard hierarchy is a tree hierarchy which is used to organize business processes of a controlling area. The highest node of a standard hierarchy is normally the first business process group. The groups created thereafter make of the remaining nodes of the standard hierarchy.
The standard hierarchy is assigned directly to the controlling area and has itself a set of business process groups assigned to it. This ensures that all business processes belonging to a controlling area are grouped together.
Example:
Sales Hierarchy
Root | Root is at the top of Hierarchy, It doesn’t have superior Nodes. |
Nodes | The upper-most node is the root. Each node has exactly one parent node (predecessor) Nodes that can be posted to refer to the hierarchy basic characteristic. Nodes that cannot be posted either text nodes or external characteristic nodes. |
Leaves | A node without lower-level nodes (successors). Consist of characteristic values for the basic characteristic. |
Hierarchy Levels | The level of the node corresponds to the number of its predecessors increasing up to the root of one All nodes on the same level of the hierarchy (nodes that are the same distance away from the root) form a hierarchy level. The root equals level 1. |
Intervals | Set of leaves that are described by its upper and lower boundaries. Can be created if a node has more than one leaf. |
STANDARD HIEARCHY IN SAP
There are different standard hierarchies available in SAP ECC like cost center, profit center, cost element etc.
There are three tables in SAP for groups in standard hierarchy.
- SETHEADER
- SETNODE
- SETLEAF
SETHEADER holds the top nodes of the groups with SETTYPE either as S or B. If SETTYPE is S, then the top node has sub groups. Then take the SETNAME from SETHEADER and filter SETNODE table with SETNAME.
To build a standard hierarchy, we have to read SETNODE for each level of the hierarchy and build the tree.
In SAP, there are many different groups such as Cost Center Group, Cost Element Group, and Profit Center Group etc. Each and every group is identified with unique code in field SETCLASS (ex: 0106 for Profit Center, 0101 for Cost Center and 0102 for Cost Element Groups etc.). If the SETTYPE is B, then the top node have reached the last sub group and with that SETNAME, filter SETLEAF with SETCLASS, SUBCLASS and SETNAME.
The following is one of the examples of how a standard hierarchy looks in SAP ECC. This hierarchy is a cost center hierarchy with group (root) node C1000 and controlling area 0001.
The details of the above cost center hierarchy are provided below:
CHARACTERISTICS | DETAILS |
Controlling Area | 0001 |
Root | C1000 |
Nodes | C1010, C1110, C1120, C1200, C1300, C1400 |
Hierarchy Levels | Highest Level – 4 (1234, 4568, 98763) |
Group Nodes | C1000, C1010, C1110, C1120, C1200, C1300, C1400, C1210, C1220, C1230, C1310, C1320, C1410, C1420, C1430, C1440, C1450 |
Cost Center (KOSTL) | 1234, 4568, 98763 |
NOTE: Either group node or cost center will be a leaf node.
The text in the above hierarchy is description of the nodes obtained from two text tables i.e. SETHEADERT for group nodes (for all hierarchies) and CSKT for cost center (specific to cost center hierarchy).
This cost center hierarchy will be used to explain implementation of standard hierarchy in SAP HANA.
IMPLEMENTATION OF STANDARD HIERARCHIES IN SAP HANA
In ECC, there are several function modules which can be used to implement as well as display standard hierarchies. But in SAP HANA there is no Standard way to create and view this type of hierarchy (like simple parent-child and level hierarchies available).
Here the above shown cost center hierarchy will be used to explain implementation and displaying a standard hierarchy in SAP HANA.
Here group (root) node and controlling area will be required initially; hence SETHEADER table will not be used. So, only SETNODE and SETLEAF tables, group (root) node, controlling area, and CSKS (cost center), CSKT (cost center text) and SETHEADERT (group nodes text) tables will be required.
The below steps will be followed for implementation of this hierarchy:
- Create a scripted calculation view to get parent child relation of the hierarchy using, SETNODE, SETLEAF and the module table i.e. CSKS for cost center, CSKA for cost element, CEPC for profit center etc. As in this case, we are implementing cost center hierarchy, so CSKS table will be used.
- To get the description texts, join the text tables to the above created view. The text tables SETHEADERT for group nodes and specific text tables for the module like CSKT for cost center, CEPCT for profit center text, etc. will be used. As in this case, we are implementing cost center hierarchy, so CSKT table will be used.
- Flatten the above parent child-relation view (with texts/description) to get level wise data/hierarchy.
STEP 1: CREATE A SCRIPTED CALCULATION VIEW TO GET PARENT-CHILD RELATION
The code below will be used to implement the above given cost center hierarchy as a parent child relation in a scripted calculation view.
Note: By doing some changes you can implement this code for other FI/CO hierarchies like cost element, profit center etc., doing some minor changes in the code. (Example: for profit center, use CEPC table will be used instead of CSKS and changing some key fields like PRCTR instead of KOSTL, and some basic conditions will be changed like SETCLASS = 0106, instead of 0101)
The following are the details of the scripted calculation view:
NAME | TYPE | PARAMETER CASE SENSITIVE |
CA_HIERARCHY | Scripted | True |
Input Parameters:
NAME | TYPE | SIZE | COMMENTS |
ControllingArea | NVARCHAR | 12 | to input controlling area of the hierarchy |
Group_Root_Node | NVARCHAR | 24 | to input the group node (root node) |
Output Columns:
NAME | TYPE | SIZE | COMMENTS |
MANDT | NVARCHAR | 3 | Client |
PARENT | NVARCHAR | 24 | Parent group node |
GROUP_NODE | NVARCHAR | 24 | Group Node (it can also be a leaf node) |
COST_CENTER | NVARCHAR | 24 | Cost Center (this can only be a leaf node) |
LEVEL | INTEGER |
-
| Level of the group node/cost center (for root node, LEV = 1) |
CONTROLLING_AREA | NVARCHAR | 4 | Hierarchy controlling area (it will be same as the input controlling area) |
Conditions:
CONDITON | DETAILS |
SETCLASS = ‘0101’ | This condition will be same for all cost center hierarchies (for profit center- 0106, for cost element – 0102, etc.) |
Source Code:
/********* Begin Procedure Script ************/
/* Compute the Cost Center Standard Hierarchy */
NUM int := 0;
LEV int := 1;
BEGIN
/*In case Group_Root_Node is empty, retrieve only leaf(Cost center) node from SETLEAF table*/
if :Group_Root_Node = '' then
LT_CC_TMP = SELECT MANDT AS MANDT, NULL AS PARENT, NULL AS GROUP_NODE, VALOPTION AS VALOPTION, VALFROM as VALFROM, VALTO as VALTO, 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM SETLEAF
WHERE SETCLASS = '0101' and SUBCLASS = :ControllingArea;
var_out = SELECT MANDT, PARENT, GROUP_NODE, VALFROM AS COST_CENTER, LEVEL, CONTROLLING_AREA
FROM :LT_CC_TMP;
LT_CC_TMP2 = SELECT CC.MANDT AS MANDT, NULL AS PARENT, CC.GROUP_NODE AS GROUP_NODE, CSKS.KOSTL AS COST_CENTER, CC.LEVEL AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM :LT_CC_TMP as CC inner join CSKS as CSKS ON (CSKS.MANDT = CC.MANDT and CSKS.KOSTL >= CC.VALFROM and CSKS.KOSTL <= CC.VALTO)
WHERE CSKS.KOKRS = :ControllingArea;
var_out = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :var_out
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_CC_TMP2;
/*If Group_Root_Node is empty, empty cost center should also be considered*/
LT_CC_TMP_2 = SELECT DISTINCT MANDT AS MANDT, NULL AS PARENT, NULL AS GROUP_NODE, '' AS COST_CENTER, 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM SETLEAF
WHERE SETCLASS = '0101' and SUBCLASS = :ControllingArea;
var_out = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :var_out
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_CC_TMP_2;
/*Retrieve all hierarchy groups and the cost center from both SETNODE and SETLEAF, incase Group_Root_Node is not empty*/
else
LT_ROOT = SELECT DISTINCT MANDT AS MANDT, NULL AS PARENT, SETNAME AS GROUP_NODE, NULL AS COST_CENTER, 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM SETNODE
WHERE SETCLASS = '0101' and SUBCLASS = :ControllingArea and SETNAME = :Group_Root_Node;
/*inacase for a group node, there is no subgroup, then it will not be in SETNODE, but only in SETLEAF*/
LT_ROOT2 = SELECT DISTINCT MANDT AS MANDT, NULL AS PARENT, SETNAME AS GROUP_NODE, NULL AS COST_CENTER, 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM SETLEAF
WHERE SETCLASS = '0101' and SUBCLASS = :ControllingArea and SETNAME = :Group_Root_Node;
LT_HIERARCHY = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_ROOT
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_ROOT2;
while 1 = 1 do
LT_HIERARCHY_TMP = SELECT part.MANDT AS MANDT, part.SETNAME AS PARENT, part.SUBSETNAME AS GROUP_NODE, NULL AS COST_CENTER, :LEV + 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM :LT_HIERARCHY as main inner join SETNODE as part ON (part.MANDT = main.MANDT and main.GROUP_NODE = part.SETNAME)
WHERE part.SETCLASS = '0101' and part.SUBCLASS = :ControllingArea and main.LEVEL = :LEV;
SELECT COUNT(*) INTO NUM FROM :LT_HIERARCHY_TMP;
if :NUM = 0 then
break;
end if;
LT_HIERARCHY = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_HIERARCHY
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_HIERARCHY_TMP;
LEV := :LEV + 1;
end while;
LT_CC_TMP = SELECT CC.MANDT AS MANDT, CC.SETNAME AS PARENT, NULL AS GROUP_NODE, CC.VALOPTION AS VALOPTION, CC.VALFROM as VALFROM, CC.VALTO as VALTO, CC_gr.LEVEL + 1 AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM :LT_HIERARCHY as CC_gr inner join SETLEAF as CC ON (CC.MANDT = CC_gr.MANDT and CC_gr.GROUP_NODE = CC.SETNAME)
WHERE CC.SETCLASS = '0101' and CC.SUBCLASS = :ControllingArea;
LT_CC = SELECT MANDT, PARENT, GROUP_NODE, VALFROM AS COST_CENTER, LEVEL, CONTROLLING_AREA
FROM :LT_CC_TMP;
LT_CC_TMP2 = SELECT CC.MANDT AS MANDT, CC.PARENT AS PARENT, CC.GROUP_NODE AS GROUP_NODE, CSKS.KOSTL AS COST_CENTER, CC.LEVEL AS LEVEL, :ControllingArea AS CONTROLLING_AREA
FROM :LT_CC_TMP as CC inner join CSKS as CSKS ON (CSKS.MANDT = CC.MANDT and CSKS.KOSTL >= CC.VALFROM and CSKS.KOSTL <= CC.VALTO)
WHERE CSKS.KOKRS = :ControllingArea;
LT_CC = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_CC
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_CC_TMP2;
var_out = SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_HIERARCHY
UNION
SELECT MANDT, PARENT, GROUP_NODE, COST_CENTER, LEVEL, CONTROLLING_AREA from :LT_CC;
end if;
END /********* End Procedure Script ************/
After executing the view for the given hierarchy, and providing the following values for the two input parameters.
The following output of the above scripted view, for the given cost center hierarchy:
The above shown is the parent child relation of the hierarchy with cost center.
STEP 2: JOIN THE SCRIPTED HIERARCHY VIEW WITH THE TEXT TABLES TO GET DESCRIPTION TEXT
In order to get the description of a hierarchy, we need to join the scripted view (CA_HIERARCHY), with the two text tables i.e. SETHEADERT for group nodes and specific text tables for the module like CSKT for cost center, CEPCT for profit center text, etc. will be used. As in this case, we are implementing cost center hierarchy, so CSKT table will be used.
The following are the details of the calculation view:
NAME | TYPE | DATA CATEGORY |
CA_HIERARCHY_DESCRIPTION | Graphical | Dimension |
Required Tables/Views:
NAME | VIEW/TABLE | COMMENTS |
CA_HIERARCHY | VIEW | Scripted hierarchy view |
SETHEADERT | TABLE | Table containing description text for groups (i.e. COSTCENTERGROUP in this view) |
CSKT | TABLE | Table containing description text for cost center. |
Input Parameters:
NAME | DATA TYPE | SIZE | COMMENTS |
ControllingArea | NVARCHAR | 12 | to input controlling area of the hierarchy (map with that of the scripted view, CA_HIERARCHY) |
Group_Root_Node | NVARCHAR | 24 | to input the group (root) node (map with that of scripted view, CA_HIERARCHY) |
Output Columns:
NAME | DATA TYPE | SIZE | COMMENTS |
MANDT | NVARCHAR | 3 | Client |
PARENT | NVARCHAR | 24 | Parent group node |
LEVEL | INTEGER | - | Level of the group node/cost center (for root node, LEV = 1) |
CONTROLLING_AREA | NVARCHAR | 4 | Hierarchy controlling area (it will be same as the input controlling area) |
LEVEL | NVARCHAR |
24
| Calculated column for level |
Level_Description | NVARCHAR | 50 | Calculated Column for level text |
Join details:
LEFT TABLE | LEFT FIELDS | RIGHT TABLE | RIGHT FIELDS | JOIN TYPE | JOIN NAME |
CA_HIERARCHY | MANDT, GROUP_NODE | SETHEADERT | Client | TEXT | Join_1 |
JOIN_1 | MANDT, COST_CENTER, CONTROLLING_AREA | CSKT | MANDT, KOSTL, KOKRS | TEXT | Join_1 |
Filter details:
FILTER FIELDS | TABLE | FILTER CONDITION | COMMENTS |
SETCLASS | SETHEADERT | SETCLASS = 0101 | SETCLASS specific to cost center |
SUBCLASS | SETHEADERT | SUBCLASS = 0001 | SUBCLASS specific to controlling area |
As explained earlier, that the leaf node will either be a group node or cost center; or cost center will always be a leaf node. So, here these two columns will be combined into one, creating a calculated column, and doing the same for description.
Following are the two calculated columns:
NAME | DATA TYPE |
Level | NVARCHAR |
Level_Description | NVARCHAR |
SIZE | FORMULA |
50 | if(isnull("GROUP_NODE"),"COST_CENTER","GROUP_NODE") |
50 | if(isnull("DESCRIPT"),"LTEXT","DESCRIPT") |
Shown below is how the semantics will look:
Notice the hidden columns (As they are not required)
Shown below is how the graphical view will look:
Shown below is how the joins will look like:
Join_1
Join_2
OUTPUT:
Provide the values to the input parameters:
The final output of this view:
STEP 3: FLATTEN THE ABOVE VIEW TO GET LEVEL WISE DATA
The above created view with the group and cost center texts, will be flattened in this step.
This is done in order to get level wise data, i.e. each row for each traversal from root node to a leaf node. And addition to that, a calculated column will be created, which will contain leaf node of each field. This calculated column can be used to join the hierarchy with the transaction data (which is one of the major reasons to flatten this hierarchy).
The following are the details of the calculation view:
NAME | TYPE | DATA CATEGORY |
CA_HIERARCHY_DESCRIPTION | Graphical | Dimension |
Required Tables/Views:
NAME | VIEW/TABLE | COMMENTS |
CA_HIERARCHY_DESCRIPTION | VIEW | Scripted hierarchy view |
Input Parameters:
NAME | DATA TYPE | SIZE | COMMENTS |
ControllingArea | NVARCHAR | 12 | to input controlling area of the hierarchy (map with that of CA_HIERARCHY_DESCRIPTION view) |
Group_Root_Node | NVARCHAR | 24 | to input the group (root) node (map with that of CA_HIERARCHY_DESCRIPTION view) |
Output Columns:
NAME | DATA TYPE | SIZE | COMMENTS |
MANDT | NVARCHAR | 3 | Client |
CONTROLLING_AREA | NVARCHAR | 4 | Hierarchy controlling area (it will be same as the input controlling area) |
LEVEL1 | NVARCHAR | 24 | Flattened column for level1 |
LEVEL1_DESCRIPTION | NVARCHAR | 50 | Flattened column for level1 text |
LEVEL2 | NVARCHAR | 24 | Flattened column for level2 |
LEVEL2_DESCRIPTION | NVARCHAR | 50 | Flattened column for level2 text |
LEVEL3 | NVARCHAR | 24 | Flattened column for level3 |
LEVEL3_DESCRIPTION | NVARCHAR | 50 | Flattened column for level3 text |
LEVEL4 | NVARCHAR | 24 | Flattened column for level4 |
LEVEL4_DESCRIPTION
| NVARCHAR |
50
| Flattened column for level4 text |
JOIN_FIELD | NVARCHAR | 50 | Calculated column to create a join field (to join this hierarchy with transaction tables) |
The maximum level here is 4, so the flattening here will be done till level 4. If the hierarchy goes beyond level 4, then further flattening will be required.
Join details:
LEFT TABLE | LEFT FIELDS | RIGHT TABLE |
CA_HIERARCHY_DESCRIPTION (LEVEL = 1) | MANDT, LEVEL | CA_HIERARCHY_DESCRIPTION (LEVEL = 2) |
CA_HIERARCHY_DESCRIPTION (LEVEL = 2) | MANDT, LEVEL | CA_HIERARCHY_DESCRIPTION (LEVEL = 3) |
CA_HIERARCHY_DESCRIPTION (LEVEL = 3) | MANDT, LEVEL | CA_HIERARCHY_DESCRIPTION (LEVEL = 4) |
RIGHT FIELDS | JOIN TYPE | JOIN NAME |
MANDT, PARENT | Left Outer | Join_1 |
MANDT, PARENT | Left Outer | Join_2 |
MANDT, PARENT | Left Outer | Join_3 |
Filter details:
FILTER FIELDS | TABLE/VIEWS | FILTER CONDITION | COMMENTS |
LEVEL | CA_HIERARCHY_DESCRIPTION | LEVEL = 1 | This is to get level1 node and description |
LEVEL | CA_HIERARCHY_DESCRIPTION | LEVEL = 2 | This is to get level2 node and description |
LEVEL | CA_HIERARCHY_DESCRIPTION | LEVEL = 3 | This is to get level3 node and description |
LEVEL | CA_HIERARCHY_DESCRIPTION | LEVEL = 4 | This is to get level4 node and description |
Calculated columns:
NAME | DATA TYPE |
JOIN_FIELD | NVARCHAR |
SIZE | FORMULA |
24 | if(isnull("LEVEL4"),if(isnull("LEVEL3"),if(isnull("LEVEL2"),"LEVEL1", "LEVEL2"), "LEVEL3"),"LEVEL4") |
Shown below is how the graphical view will look:
Shown below is how the joins will look like:
This is the join between CA_HIERARCHY_DESCRIPTION (LEVEL=1) and CA_HIERARCHY_DESCRIPTION (LEVEL=2) i.e.Join_1.
So the following is how the semantics will look:
OUTPUT:
Provide the values to the input parameters:
The final output of this view:
Source: scn.sap.com
No comments:
Post a Comment