How to Use Hierarchies in Queries in SAP BW/4HANA

How to Use Hierarchies in Queries in SAP BW/4HANA

Hierarchies are a powerful way to organize and analyze data in SAP BW/4HANA. They allow you to group and aggregate data according to different levels of detail, such as regions, products, or customers. Hierarchies can also help you to drill down or drill up the data, and to display it in a tree-like structure.

In this blog post, we will explain what hierarchies are, how they work, and how to use them in queries in SAP BW/4HANA. We will also show you some examples of queries with hierarchies and how to create and maintain hierarchies using the web cockpit.

What are hierarchies in SAP BW/4HANA?

A hierarchy is a set of nodes that are connected by parent-child relationships. A node can be either a characteristic value (such as a country or a product) or a group of characteristic values (such as a region or a product category). A node can have one or more child nodes, but only one parent node. The topmost node of a hierarchy is called the root node, and the nodes that have no child nodes are called the leaf nodes.

A hierarchy can be defined for any characteristic that has the hierarchy property enabled in InfoObject maintenance. A characteristic can have multiple hierarchies, but only one hierarchy can be active at a time. A hierarchy can be either time-dependent or time-independent, depending on whether the node structure changes over time or not. A hierarchy can also have intervals, which are ranges of characteristic values that are treated as one node.

Hierarchies are stored in SAP BW/4HANA as master data tables, and they can be created and maintained using the web cockpit or external tools. Hierarchies can also be delivered by SAP or imported from other sources.

How to use hierarchies in queries in SAP BW/4HANA?

To use hierarchies in queries in SAP BW/4HANA, you need to add the hierarchy basic characteristic (the characteristic for which the hierarchy is defined) to the rows or columns of the query. Then, you need to select the hierarchy that you want to use from the list of available hierarchies for that characteristic. You can also specify the level of detail that you want to display by selecting the node level or the interval level.

When you execute the query, the data will be grouped and aggregated according to the hierarchy structure. You can also expand or collapse the nodes to see more or less detail. You can also use filters, variables, formulas, exceptions, and conditions on hierarchies to further customize your query.

Here is an example of a query with a hierarchy on the Ship-To Party characteristic:

The query uses the Ship-To Party Hierarchy, which has the following structure:

  • Root Node
  • Europe
    • Germany
    • Berlin
    • Munich
    • France
    • Paris
    • Lyon
  • Asia
    • China
    • Beijing
    • Shanghai
    • India
    • Delhi
    • Mumbai

The query result will look something like this:

Ship-To PartySales OrganizationNet Value
Root Node1000100000
Europe100060000
Germany100030000
Berlin100015000
Munich100015000
France100030000
Paris100020000
Lyon100010000
Asia100040000
China100025000
Beijing100015000
Shanghai100010000
India100015000
Delhi10008000
Mumbai10007000

You can see that the data is grouped and aggregated according to the hierarchy nodes. You can also expand or collapse the nodes to see more or less detail.

How to create and maintain hierarchies using the web cockpit?

In SAP BW/4HANA, you can create and maintain hierarchies using the web cockpit. To do this, you need to follow these steps:

  1. Open the web cockpit and navigate to the InfoObject Catalogs tab.
  2. Select the hierarchy InfoObject for which you want to create or maintain a hierarchy.
  3. Click on the Create Hierarchy button to create a new hierarchy, or select an existing hierarchy and click on the Edit Hierarchy button to modify it.
  4. Enter a name and a description for the hierarchy, and specify the version dependency and the time dependency options.
  5. Add nodes to the hierarchy by dragging and dropping characteristic values from the Available Values pane to the Hierarchy Structure pane. You can also create groups of characteristic values by clicking on the Create Group button, or intervals by clicking on the Create Interval button.
  6. Save and activate the hierarchy.

You can also import hierarchies from external sources, such as flat files, SAP ERP, or SAP S/4HANA, by clicking on the Import Hierarchy button and following the instructions.

Conclusion

Hierarchies are a useful way to organize and analyze data in SAP BW/4HANA. They allow you to group and aggregate data according to different levels of detail, and to display it in a tree-like structure. You can use hierarchies in queries in SAP BW/4HANA by adding the hierarchy basic characteristic to the rows or columns of the query, and selecting the hierarchy that you want to use. You can also create and maintain hierarchies using the web cockpit or external tools.

We hope that this blog post has helped you to understand how to use hierarchies in queries in SAP BW/4HANA. If you have any questions or feedback, please leave a comment below.

Disclaimer: This content is generated by AI.