Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions →  ABAP CDS - DEFINE HIERARCHY →  ABAP CDS - DEFINE HIERARCHY, element_list 

ABAP CDS - DEFINE HIERARCHY, element

Other versions: 7.31 | 7.40 | 7.54

Syntax


... [@element_annot1] 
    [@element_annot2]
    ...
       [KEY] { _assoc                   [AS alias] }
           | { element                  [AS alias] }
           | { $node.hierarchy_attribute AS alias  }
    [@<element_annot1]
    [@<element_annot2] ...

Alternatives

1. ... _assoc

2. ... element
3. ... $node.hierarchy_attribute

Extras

1. ... @element_annot ... @<element_annot

2. ... KEY
3. ... AS alias

Effect

Specifies an element in the element list of a CDS hierarchy. The names of the elements in a hierarchy must be unique and must be in the same namespace as the parameters of the CDS hierarchy.

Alternative 1

... _assoc

Effect

_assoc can be used to make the CDS hierarchy publish a CDS association that itself is published by the CDS view cds_view specified after SOURCE in its SELECT list. The name of a CDS association can be specified for _assoc but path expressions are not possible.

The CDS hierarchy publishes the CDS association for use in CDS views or in ABAP SQL:

The current CDS hierarchy is the source data source of the published CDS association and any join expressions created for a path expression from the CDS association use the current CDS hierarchy as their left side. All fields of the source data source of the CDS association that occur in the ON condition must also be specified as elements of the current element list.

A CDS association published in this way is, like any element, part of the element list. It is not, however, part of the results set or a component of a type defined in ABAP with respect to the CDS hierarchy. If no alternative element name alias is defined, the element name is defined by the name of the CDS association.


Note

When a CDS association is published, care should be taken that the publisher hierarchy itself is the source data source of the published CDS association and not the data source of the view. More specifically, when CDS associations are published that were already published by the source of the hierarchy, the hierarchy replaces the original view as the source data source of the CDS association. The left side of an instance of a join expression created for the published CDS association is the results set of the hierarchy.

Alternative 2

... element

Effect

element can be used to specify an element of the CDS view cds_view specified after SOURCE. This element is part of the results set of the CDS hierarchy and a component of a type defined in ABAP with respect to the CDS hierarchy.


Note

When the hierarchy is defined in ABAP SQL, the element is a regular component of the hierarchy in the results list, if or ...~ are used in the SELECT list.

Alternative 3

... $node.hierarchy_attribute

Effect

$node.hierarchy_attribute can be used to specify a hierarchy attribute hierarchy_attribute after the prefix $node. The names of all hierarchy attributes can be specified for hierarchy_attribute. In this case, AS ALIAS must be used to define an alternative element name, which cannot be the name of a hierarchy attribute.

This element is part of the results set of the CDS hierarchy and a component of a type defined in ABAP with respect to the CDS hierarchy. When the CDS hierarchy is accessed, the element contains the respective value of the hierarchy attribute for each row.


Notes

  • When the hierarchy is defined in ABAP SQL, the element is a regular component of the hierarchy in the results list, if * or ...~* are used in the SELECT list.

  • When the hierarchy is accessed in ABAP SQL, the associated additional hierarchy column can be used to access the hierarchy attribute.

  • It is practical to include a hierarchy attribute in the element list of a CDS hierarchy explicitly either if it is required when other CDS entities access the CDS hierarchy, or if it is a component of a structured type in ABAP that references the CDS hierarchy.

Addition 1

... @element_annot

Effect

Specifies annotations for the element. The annotations can be specified before the element using @element_annot or after the element using @<element_annot.


Note

Element annotations can be used to annotate the elements and CDS associations of a CDS hierarchy with semantic attributes.

Addition 2

... KEY

Effect

KEY is used to define the current element as the key element of the current CDS hierarchy. Those elements of the element list can be defined as key elements that are placed without gaps at the start of the list. The key elements of the CDS entity are evaluated as follows if they are used as a data source of a SELECT statement in ABAP SQL:

If a CDS role defined for a CDS entity is evaluated when the entity is accessed, its key elements must identify a unique row in the results set. If this is not the case, the internal instance of access control can produce duplicate entries or even incorrect results when aggregate functions are used. If a unique key cannot be determined for a CDS entity, no key element should be defined. A different instance of access control is then produced internally, which is less efficient.

Otherwise, the key elements of the CDS entity are used to document the semantics of the data model. The addition KEY is then ignored when the CDS hierarchy is activated and when other accesses are performed in program executions.


Notes

  • In the ABAP SQL syntax check, the key elements are used in places where the key is respected.

  • The key elements are not relevant for the uniqueness of rows within the results set of the CDS hierarchy, which means that exceptions can be raised when making assignments to internal tables with appropriately unique table keys.

Addition 3

... AS alias

Effect

Defines an alternative element name for the current element. The alternative element name replaces the actual name of the element. When the current CDS hierarchy is accessed, the alternative element names must be used instead of the actual name.

Continue

ABAP CDS - DEFINE HIERARCHY, element_annot