Technology Blog Posts by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Sefan_Linders
Product and Topic Expert
Product and Topic Expert
19,828

In the previous blog, we provided an overview of the new features introduced with the Hierarchy with Directory. In this blog, we'll guide you through creating a basic Hierarchy with Directory, starting from scratch and progressing to the data preview in an Analytic Model. Our focus is on simplicity, ensuring you grasp the fundamental concepts with minimal complexity. To keep it simple, we use data from local tables, before moving on to data from SAP S/4HANA or SAP BW in future posts. However, the model is complete and comes with a few lines of transaction and master data. In our upcoming blog, we'll enhance the model by introducing advanced elements such as language-dependent texts, additional node types, and time-dependency features.
This blog is part of a series in which we introduce the Hierarchy with Directory:

  1. An Introduction to Hierarchy with Directory
  2. Modeling a basic Hierarchy with Directory (this blog)
  3. Modeling an advanced Hierarchy with Directory
  4. Create SAP S/4HANA GL Account Hierarchy within SAP Datasphere through Community Content
  5. Walkthrough of different Enterprise Scenarios via Community Content package – GL Account External Hi...
  6. Explanation of Community Content Package - GL Account External Hierarchy via Replication Flow
  7. Order siblings in a Hierarchy with Directory

Figure 1: One of the hierarchies created in this blog post

The data model in its most basic form

Our model showcases product sales within a product hierarchy. For this, we need to create at least four different views, as illustrated in Figure 2. We need views of the following Semantic Usage:

  1. Fact (Transactions), with transactions of products sold.
  2. Dimension (Product), that lists the unique product instances.
  3. Hierarchy with Directory (Product Hierarchy), which contains the parent-child relationships between the hierarchy nodes, and the definition of all hierarchy semantics.
  4. Hierarchy Directory (Product Hierarchy Directory), which lists all the hierarchies.

The figure below shows the associations between these four views, and the minimal column set that we need for the hierarchy to function. Each of the views need a data set underneath, which we provide using local tables and in which we entered manually a few records. Missing in the figure is the Analytic Model. We will need it when previewing the data, but for now we just want to focus on the core elements needed.

Figure 2: Minimum set of objects to showcase a Hierarchy with Directory

The sample data

Each view reads from a local table with a few sample records. Figure 3 lists our sales transactions. Yes, we know, nine records are nothing close to reality, but it serves its purpose.

Figure 3: Sample transaction data of product sales

Figure 4 lists the unique Product IDs. Usually, a product dimension would have all kinds of master data, but again, we keep it as simple as possible and therefore this table has just one column.

Figure 4: Minimal data set for Product dimension

In this blog we will work with two data-driven hierarchies, which means that we add two entries to the Product Hierarchy Directory as displayed in Figure 5. If S/4HANA would be your source, you might have many more of these entries, with additional semantics such as date validity intervals. We come back on those additional semantics in the next post.

Figure 5: Minimal form of a Hierarchy Directory with two entries

Figure 6 illustrates the hierarchy's sample data, detailing the parent-child node relationships for our two hierarchies. The data here is already organized according to how the Hierarchy with Directory will consume it, as we will see later.
It is important to understand that there are two keys at play here:

    • One key specifies the parent-child relationship. In our data model, this is field Node ID. It is the child of the parent-child relationship.
    • A second key to identify the respective node’s real In our data model, this is Product ID or Product Category ID. The Node Type field determines which of the two keys should be considered. Later, we will see that dimensions can be associated to this key, making them in fact dimension keys.

Study the below sample data, and take note of how a single product, like OATMILK_1, is categorized differently across two hierarchies, marked respectively green and purple. In the green hierarchy, called DRINKS_OR_NOT, the leaf node is of Node Type PRODUCT. Therefore, the Product ID determines the real key, OATMILK_1. In this hierarchy table its Node ID, the child, is 4. Its parent is Node ID 0, and as you can see, for that node the Node Type is PRODUCT_CATEGORY, and the real key therefore is Product Category ID.

Figure 6: The hierarchy node relationships for two different hierarchies

The views

Finally, it is time to put the semantics in place by creating the views. The Transactions view is of type Fact, and the Product view is of type Dimension. We’re assuming no further explanation is needed on those views, so we continue here with the final two views.

Hierarchy Directory

The hierarchy directory is, at its most basic, just a list of the different hierarchies with a label, modeled as a dimension. The dimension requires a key field and a label field. In our case this is Hierarchy Name and Hierarchy Label. You can choose the names of the field yourselves, but this dimension will always at least a key and a label field. Make sure the label field is configured as Text and assigned to the Hierarchy Name field, as you can see in Figure 7. This label will show up in our reporting tool when we want to select the active hierarchy.
We create this directory dimension first, because we will need to refer to it when we build the hierarchy view.

Figure 7: Column semantics for Product Hierarchy Directory

The Hierarchy with Directory

And then it is time for the hierarchy itself, for which we follow these steps:

  1. Create a view with “Hierarchy with Directory” as its Semantic Usage. In below figure you can see that we are using a SQL view, but you can use a graphical view as well.
  2. Consume the table with the parent-child relationships, in our case LT_NODES, of which the content was shown in Figure 6.
  3. Create an association to the Product Hierarchy Directory between the Hierarchy Name field from the hierarchy itself to the hierarchy directory.
  4. Choose “Hierarchy with Directory Settings” as you can see in Figure 8. This opens up the settings dialog.

 

Figure 8: Selecting the settings for the Product Hierarchy

In the settings dialog we do the following, according to the numbering in Figure 9:

  1. Choose the parent field.
  2. Choose the child field.
  3. Choose the Hierarchy Name column, which should be the column from which we created an association to the Product Directory View.
  4. The Hierarchy Directory Entity should now be displayed automatically.
  5. Choose the column that defines the Node Type.
  6. Our leaf node is of node type value PRODUCT, so we manually enter that value here.
  7. We choose the column that the Product ID is in. This will be the column showing up later as the node value.
  8. Choose “Set as Leaf” if not already set.

Figure 9: The Hierarchy with Directory settings

9. Add another Node Type Value by clicking the “+” sign.
10. Enter the Node Type Value
11. Choose Product Category ID as the Node Type Value

Figure 10: Adding the Product Category node type value

As you can see, it is also possible to add multiple columns to define the target fields for a node type. This allows you to use compound keys, which you will need for certain S/4 or BW hierarchies.
That’s it for configuring the Product Hierarchy view. After deploying the Product Hierarchy, go to the Product dimension, and create an association of type Hierarchy with Directory to the Product Hierarchy view.

The Analytic Model

To preview the transactions as part of the hierarchy, we need an Analytic Model to consume the created objects. This is straightforward:

  1. Create a new Analytic Model, and drag the Transaction view in.
  2. Import the associations when you are prompted for it.
  3. Select Amount as the required measure.

This is all you need to do before previewing the data. Even when you’re just playing around, it’s helpful to save and deploy the Analytic Model. In general, whenever you make changes to any of the objects and you want to make sure all changes are properly propagated, just redeploy the Analytic Model. This will redeploy all related objects and ensure that the Analytic Model is aware of your change.

Data preview

To view your data in the Analytic Model, we simply follow these steps:

  1. Choose Preview to go to the preview screen.
  2. Insert Product ID into the rows, creating a straightforward list of sales per product.
  3. As outlined in Figure 11, hover over the Product ID entry in the Rows section, then choose Hierarchy, and then choose Select Hierarchy. A dialog pops up to choose the hierarchy (see Figure 12).
  4. Change the display format to Description as shown in Figure 13, which will showcase the node text rather than the node ID.
  5. Take a moment to appreciate the final display.

Figure 11: Selection of a hierarchy in data preview of an Analytic Model

Figure 12: Hierarchy selection

 

Figure 13: Change the hierarchy display

Figure 14 and Figure 15 show the same transactions, aggregated in the two different hierarchies. Again, you could have a look at Product ID OATMILK_1 and its assignment according to the data in Figure 6.

Figure 14: The Drinks or not hierarchy

Figure 15: The More categories hierarchy

Conclusion

In this blog, we've guided you through the creation of a basic yet functional set of tables and views, demonstrating a Hierarchy with Directory in SAP Datasphere. You now have a solid understanding of the foundational aspects. Hierarchies sourced from SAP S/4HANA or SAP BW often necessitate additional features. Therefore, we extend our model in the next blog: Modeling an advanced Hierarchy with Directory.

19 Comments
Roberth_Reyes
Discoverer
0 Kudos

Hi Sefan_Linders

Thanks a lot for your very detail explination, I'm trying to use this new feacture of hierarchy with directory following all your intructions but when a display the hierarchy on the data preview for my analitical model I Can see the hierarchy structure but always get the IDs  of my used dimension, even that I change the representation to description I can only see the IDs but not the descriptions.

Could you please advise me with this? 

Roberth_Reyes_0-1717518227062.png

Many thanks in advance. 

SAP Datasphere 

 

Roberth_Reyes
Discoverer

Hi, 

I've solved the issue previously described with texts, the problem was that I created all the hierarchy structure only in tables, then when I created views over those tables and use them in the data model, the hierachy started to work fine.

 

Regards. 

RossR
Explorer
0 Kudos

Hi @Roberth_Reyes@Sefan_Linders 

I am having a similar issue with the hierarchy, maybe worse, wherein hierarchies only display the key fo the hierarchy table and not the semantically relevant fields. For example the following is the key of the hierarchy table (or view, I tried all sorts of combinations as you suggested above).

RossR_5-1721263189155.png

RossR_6-1721263202756.png

My expectation is that at least the key from the associated field should be shown based on the following configuration.

RossR_2-1721262747306.png

RossR_3-1721262763026.png

I have set the text associations as follows.

RossR_4-1721263168794.png

Any thought on where this has gone wrong? I have tried a tonne of other things as well without any success.

 

 

 

 

 

Sefan_Linders
Product and Topic Expert
Product and Topic Expert

@RossR in my blog I am not assigning labels within the HwD view itself. In fact, I'm not assigning any texts in my basic example. In the advanced (next) blog on modeling, I associate separate dimensions that again associate a text view. 

I've reproduced your setup and my conclusions:

  • In your screenshots, it seems that you are not using your Node Type Values in the right way. You have selected column NODETYPE as containing the types, but these types you are not using in the "Node Type Value" definition. E.g., for CHILDID "00000001" your NODETYPE='0HIER...', but you are not using that node type in your HwD definition. There you use 'Text Node' as the node type value, but I do not see that value in your NODETYPE column. If you fix this, you might actually see at least the selected columns (e.g. what you have selected under "Column 1") as your description.
  • I would argue that your method of assigning labels within the HwD view, is not supported. Instead, work according to the setup in my blog. That means:
    • From the dimension to which you associate the HwD view (Product in my examples), associate the text view for the leaf nodes 
    • From the HwD view, associate a dimension with itself an associated text view to the intermediary nodes. You might not need the dimension and directly associate a text view to the HwD view.
RossR
Explorer
0 Kudos

@Sefan_Linders, thank you for that, correcting the mapping in the HwD Node Type Values appears to be most of the issue resolved. The hierarchy is still showing the Node ID for the Key which I find a bit odd. I suppose if I cannot find a way to resolve this I can substitute the numeric IDs with the corresponding actual dimension IDs.

I have not yet fully followed your example verbatim because I am hoping to try and avoid using Text tables (the client is a single language business and it thus seems unnecessary). Given that I still have a deficiency I will try using the text tables and also try using views over the base tables as Roberth has mentioned above.

RossR_0-1721311001708.png

Something that I have found worrying during my many attempts to get this to work is that the configuration only appears to have been updated when I delete the Fact view and Analytical model and re-build them from scratch. For example I now have a mostly working model, as shown above, where the fact data is associated with the REP_ITEM dimension. I have other models that are also associated with the REP_ITEM dimension where the hierarchy for the exact same dimension is not being displayed correctly. Have you experience this, could this be the result of some form of caching?

RossR_1-1721311699782.png

 

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @RossR the hierarchy showing the Node ID for the Key is a limitation I listed in my blog, and your workaround is the one that would solve that indeed. 

Indeed, configuration changes do not always have effect, if they are made in objects underlying the Analytic Model. In my tests, it showed that re-deploying the Analytic Model solved this, as this usually also redeploys the dependent objects. I stated this in my blog as well. Last week, someone reported that his changes only took effect after redeploying all involved objects. The latter you can try from the data builder overview using the mass deploy option.

RossR
Explorer
0 Kudos

@Sefan_Linders as an update to the 'worry' above, I found if I remove the REP_ITEM dimension from the Analytical model, deploy the model, preview the model, exit the model, go back into the model, add the dimension back into the model, re-deploy the model and then return to the preview that the model is reflecting the changes to the hierarchy configuration. This I can live with.

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

@RossR removing and adding should not be necessary. Try my approach listed in my previous response. If that does not work, we should file an incident to get this fixed.

rmuhuri
Participant
0 Kudos

Hi Sefan

When I tried to duplicate your model , I had errors. Below is my association as you mentioned. 

rmuhuri_0-1731293609594.png

After that I have problems in assigning the child and Hierarchy column name . It pops in the drop box but it does not stick. 

rmuhuri_1-1731293838650.png

How do I resolve that ? 

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @rmuhuri did you also assign the label semantics to the HIERARCHY_LABEL?

Sefan_Linders_0-1731314922104.png

It's anyhow strange behavior that you can select the column but then it disappears again. It could be a bug, but just to check: are you using a compatible browser such as Chrome? Also, open the develop tools console and see if there is an error thrown that indicates why the column is dropped again after selection.

rmuhuri
Participant
0 Kudos

Yeah dont know why this is happening, I did do the above thing that you suggested (label semantics to the HIERARCHY_LABEL)

 

I redid the whole scenario again but its still happening.

 

rmuhuri_0-1731333762873.png

 

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @rmuhuri it seems you have not defined HIERARCHY_NAME and NODE_ID as keys. Close this box, go to the attributes section and define them as key, or go to the hierarchy table source that contains the nodes and define the key there.

jannis
Explorer
0 Kudos

Hi,

 I was having the same issue as @Roberth_Reyes (hierachy ID showing but not texts). So I tried switching everything from tables to views. All views are ok except the Analytic Model which despite looking ok.

jannis_0-1737383221298.png

When I try to deploy it I am getting the error below.

jannis_1-1737383330252.png

Some of the things I tried is to re-redeploy all dependent objects and create a new analytic model but none of them worked. If I remove the dimension Product ID from the analytic model it works!

 Is there any way I can investigate further the error?

Best Regards.

 

 

 

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

@jannis that's hard to say without seeing the actual models you are using. Did you try creating a new Analytic Model?

jannis
Explorer
0 Kudos

Yes I already did. When I create a new Analytic Model and de-select associated dimension it works.

Update: Somehow I created a new view Hierarchy with directory identical to the one I had and now it works

utpal1pandya
Discoverer
0 Kudos

@Sefan_Linders 

Thank you very much for the nice blog. 

I have followed all the steps that you mentioned. I am using the same files that you shared and created all the necessary objects you mentioned. However, when I preview the data in analytical model, I only see the flat presentation and no hierarchy names. I tried different ways, but no luck. Could you please suggest what could be the issue

utpal1pandya_0-1746619055090.png

Here are the different objects I created

utpal1pandya_1-1746619171346.png

 

utpal1pandya_3-1746619248884.png

Product ID is associated with HwD as below

utpal1pandya_4-1746619317823.png

 

utpal1pandya_5-1746619440104.png

Hierarchy Director settings as below:

utpal1pandya_6-1746619479747.png

Please suggest and many thanks in advance

Best Regards

Utpal

Sefan_Linders
Product and Topic Expert
Product and Topic Expert
0 Kudos

@utpal1pandya to be sure can you redeploy the Analytic Model to make sure all underlying changes are taken into account?

Otherwise, I'm not sure that local tables classified as dimension and fact table are enough. You might have to wrap these tables with a view first and apply the semantics there.

utpal1pandya
Discoverer
0 Kudos

@Sefan_Linders Thank you very much for the quick help. I wrapped all the tables with the views of relevant semantic types and could see the desired result now. 

However, I could not see the Product Categories in the hierarchy. 

Below is the configuration of HWD

utpal1pandya_0-1746692732940.png

 

What could be the issue

Best Regards

Utpal

utpal1pandya
Discoverer
0 Kudos

@Sefan_Linders 

The above issue of product category is also resolved now.

utpal1pandya_0-1746702707314.png

 

Thanks