ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions
ABAP CDS - Hierarchies
A CDS hierarchy is defined in the DDL source code of a CDS data definition in the ABAP Development Tools using the statement DEFINE HIERARCHY in the CDS DDL of the ABAP Core Data Services (CDS). The name of the CDS hierarchy must match the name of the DDL source code. DDL source code in a CDS hierarchy can also be displayed in Repository Browser in ABAP Workbench.
A CDS hierarchy represents a hierarchy of rows created when the CDS hierarchy is accessed. CDS hierarchies can currently only be used when the standard database is a SAP HANA database. When a CDS hierarchy is activated, a view with the same name is created as an ABAP-managed database object on the database. This view accesses a hierarchy generator function such as HIERARCHY.
A CDS hierarchy is declared as a CDS entity cds_entity using the statement DEFINE HIERARCHY. As a data type in ABAP Dictionary, the CDS entity represents a structured type with the elements of the CDS hierarchy as components and can be used like any CDS entity.
- In ABAP CDS, the CDS entity can be used as a data source of other CDS entities.
- In ABAP, the CDS entity can be used as a data type and in ABAP SQL read statements.
- The CDS entity cannot be used as a data type for definitions of classic dictionary objects in ABAP Dictionary.
A CDS hierarchy is located in the namespace of the data types in ABAP Dictionary and in the namespace of the global object types in the class library.
When using CDS hierarchies, the handling of the special hierarchy attributes is of special importance. These attributes occur as part of the results set of the hierarchy function on the database:
- The hierarchy attributes can be accessed explicitly as follows:
- The prefix $node. can be used to list them in the element list of the CDS hierarchy and grant them an alias name. They are then applied like a regular element of the hierarchy.
- When a ABAP SQL query is applied to a CDS hierarchy, they are handled as additional hierarchy columns, regardless of their element list, and their names can be used in explicitly specified columns
- When CDS hierarchies are used, the hierarchy attributes are not respected implicitly in the following cases:
- When used as a data source of other CDS entities.
- When used as a data type.
Other versions:
7.31 | 7.40 | 7.54
Notes
- In an ABAP program, it is possible to use the method USE_FEATURES of the class CL_ABAP_DBFEATURES to check whether the current database system supports hierarchies. This requires the constant HIERARCHIES of this class to be passed to the method in an internal table.
- No CDS database view is created for a CDS hierarchy.
- A hierarchy attribute does not become part of a structured data type created by a CDS hierarchy until it is listed explicitly in the element list of the hierarchy.
- For information about client handling of CDS hierarchies, see Client Handling in CDS Hierarchies.