Hierarchies play a crucial role in business reporting and analytics, enabling users to analyze data across different levels of aggregation — for example, organizational structures, product categories, or geographical regions. Within the SAP HANA ecosystem, Core Data Services (CDS) views provide a powerful and flexible way to model such hierarchies directly at the database level. This article explains how to build hierarchies in CDS views and highlights their importance in the context of SAP-HANA-Live.
A hierarchy is a data structure that organizes information into parent-child relationships, allowing users to drill down or roll up through levels of detail. Common business examples include:
Hierarchies improve data navigation, reporting flexibility, and aggregation accuracy.
Traditionally, hierarchies were built at the application or reporting layer, often requiring complex queries or additional modeling efforts. Building hierarchies directly in CDS views offers several advantages:
SAP CDS supports hierarchies through special annotations and syntax that allow modeling hierarchical data structures declaratively.
@Hierarchy: Marks a CDS view as a hierarchy.@Hierarchy.parentChild: Defines the parent-child relationship between nodes.@Hierarchy.rootNode: Specifies the root node(s) of the hierarchy.@Hierarchy.nodeDescription: Provides descriptive text for each node.@Hierarchy.childNode: Marks the child node in the hierarchy relationship.Consider an example where you want to model an organizational hierarchy with employees and their managers.
@Hierarchy.parentChild: [{ child: 'EMPLOYEE_ID', parent: 'MANAGER_ID' }]
@Hierarchy.rootNode: ['MANAGER_ID IS NULL']
@Hierarchy.nodeDescription: 'EMPLOYEE_NAME'
define view ZOrgHierarchy
as select from employees {
key EMPLOYEE_ID,
MANAGER_ID,
EMPLOYEE_NAME,
POSITION,
DEPARTMENT
}
EMPLOYEE_ID: Unique identifier for each employee.MANAGER_ID: References the employee’s manager (parent node).MANAGER_ID IS NULL).EMPLOYEE_NAME provides the description for each node.This hierarchy can now be consumed in SAP-HANA-Live reporting tools, SAP Fiori apps, or analytical dashboards to provide drill-down and roll-up capabilities.
SAP-HANA-Live content extensively uses CDS hierarchies to deliver business-relevant analytical models with built-in organizational structures, product lines, and other hierarchical data.
Building hierarchies in CDS views is a powerful technique that leverages SAP HANA’s in-memory computing capabilities to deliver fast, consistent, and reusable hierarchical data models. In the SAP-HANA-Live context, these hierarchies are instrumental for delivering real-time, detailed operational insights and improving overall reporting efficiency. Mastering CDS hierarchies empowers SAP professionals to create sophisticated data models that support dynamic business scenarios.