Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  SELECT clauses →  SELECT - FROM →  SELECT - FROM data_source →  SELECT - FROM hierarchy_data →  SELECT - FROM hierarchy 

SELECT - FROM cds_hierarchy

Other versions: 7.31 | 7.40 | 7.54

Syntax


... cds_hierarchy[sql_para] ...

Effect

Specifies a CDS hierarchy cds_hierarchy as a hierarchy hierarchy in an ABAP SQL query. The CDS hierarchy is specified using the name cds_hierarchy defined for it after DEFINE HIERARCHY. If the CDS hierarchy has input parameters, actual parameters must be assigned to these in a parenthesized list sql_para.

The rows of the tabular results set of a CDS hierarchy specified as a data source are the hierarchy nodes of the hierarchy and their columns comprise the elements of the CDS hierarchy and the additional hierarchy columns that can be used to access the hierarchy attributes of the data source of the CDS hierarchy.


Note

When a CDS hierarchy is accessed, the hierarchy columns are read regardless of whether hierarchy attributes are listed in the element list. If a hierarchy attribute is defined as an explicit element of the CDS hierarchy, it is possible to access both the element and the additional hierarchy column in ABAP SQL.


Example

Specifies a CDS hierarchy as a data source of a SELECT statement in the program DEMO_HIERARCHY_TREE with parameter passing and explicit access to the hierarchy columns.

DATA(start_id) = 1. 

SELECT FROM demo_cds_simple_tree( p_id = @start_id ) 
       FIELDS id, 
              parent, 
              name, 
              hierarchy_rank, 
              hierarchy_tree_size, 
              hierarchy_parent_rank, 
              hierarchy_level, 
              hierarchy_is_cycle, 
              hierarchy_is_orphan, 
              node_id, 
              parent_id 
       INTO TABLE @DATA(cds_result).