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
Other versions:
7.31 | 7.40 | 7.54
Syntax
... cds_hierarchy
|
HIERARCHY( ... )
| cte_hierarchy
Effect
Specifies a hierarchy as a data source in a ABAP SQL query.
- The following can be specified:
- A hierarchy can be specified in the following places:
- As a data source
data_source
in a ABAP SQL query.
- As the source of a hierarchy navigator
- As the source of the hierarchy generator
HIERARCHY
A hierarchy is a tabular set of rows that represent the hierarchy nodes.
- A CDS hierarchy and the hierarchy generator
HIERARCHY
create their results set from the data source defined for them on the basis of a parent-child relationship itself defined in a hierarchy association.
- A CTE hierarchy represents
the hierarchy (itself specified as the only data source in the subquery of the CTE) under the name of
the CTE in the subsequent queries of the current
WITH
statement.
The columns of a hierarchy comprise the following:
- Components of the data source used when the hierarchy is created by a CDS hierarchy or created by the hierarchy generator.
- In the case of CDS hierarchies and CTE hierarchies these are precisely the components listed here.
- In the case of the hierarchy generator
HIERARCHY
, these are all components of the source of the hierarchy.
- Additional hierarchy columns. For each hierarchy node, the hierarchy columns contain its hierarchy attributes, which describe certain hierarchy-specific properties.
When a hierarchy is used as a data source in a ABAP SQL query, the additional hierarchy columns can be accessed as follows:
- In the
SELECT
list
- Hierarchy columns can be specified as regular columns using
colname
and then become part of the results set of the query.
- If
*
or...~*
is specified, hierarchy columns are not part of the results set of the query. Only the components of the source of the hierarchy are respected. In this case, the hierarchy columns are also ignored by any structure or internal table created in theINTO
clause by an inline declaration@DATA(...)
.
- In other clauses, hierarchy columns can be specified regardless of the
SELECT
list and are evaluated accordingly.
Notes
- It is possible to evaluate the hierarchy columns in a query, but this is not mandatory. In most cases, only the data content of a hierarchy is of interest and not the technical properties of the hierarchy nodes.
- On SAP HANA databases,
the results sets of CDS hierarchies plus the hierarchy generator
HIERARCHY
are created by using the SAP HANA hierarchy generator function HIERARCHY and similar. More information can be found in the documentation.
Examples
The following programs demonstrate the three ways of specifying hierarchies as the data source of a SELECT
statement while reading all possible
hierarchy columns.
- DEMO_HIERARCHY_TREE
- DEMO_HIERARCHY_PARENT_CHILD