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 cte_hierarchy

Other versions: 7.31 | 7.40 | 7.54


... +cte_hierarchy


Specifies a CTE hierarchy +cte_hierarchy as a hierarchy hierarchy in an ABAP SQL query of a WITH statement. A CTE hierarchy is a common table expression defined as a hierarchy using the addition WITH HIERARCHY.

The rows of the tabular results set of a CTE hierarchy are the hierarchy nodes of the hierarchy accessed in its subquery, including their hierarchy columns.


More specifically, a CTE hierarchy can be specified as a source of the hierarchy navigators.


Specifies a CTE hierarchy as a data source of a SELECT statement in the program DEMO_HIERARCHY_TREE with explicit access to the hierarchy columns. The data source of the subquery of the CTE hierarchy is a CDS hierarchy.

DATA(start_id) = 1. 

WITH +tree AS ( 
        SELECT FROM demo_cds_simple_tree( p_id = @start_id ) 
               FIELDS * ) 
      WITH HIERARCHY demo_cds_simple_tree 
  SELECT FROM  +tree 
         FIELDS id, 
         INTO TABLE @DATA(cte_result).


See also the example under WITH - hierarchy.