Get Example source ABAP code based on a different SAP table
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>. BEGIN_SECTION VERSION 5 OUT DDL source code in a CDS hierarchy can also be displayed in Repository Browser> in ABAP Workbench>. END_SECTION VERSION 5 OUT A CDS hierarchy represents an SQL hierarchy> 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 hierarchy> using the statement DEFINE HIERARCHY>>. As a global data type, 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 AB-SQL read statements.
The CDS entity cannot be used as a data type for definitions of dictionary objects>. A CDS hierarchy is located in the namespace of all global types> of an AS ABAP. When using CDS hierarchies, the handling of the special hierarchy attributes> is of special importance. These attributes occur as part of the result 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 CDS hierarchy.
When a AB_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 This makes it possible to specify a hierarchy attribute in the element list of the CDS hierarchy in two different ways in an AB_SQL query, either by using the name of the element or by using the name of the hierarchy column.
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.
When used as a data source in AB_SQL >, if *> or ...~*> is specified in the SELECT> > list. In these cases, only the explicit elements of the element list> are respected. These can, however, represent hierarchy attributes.