SAP SELECT HIERARCHY
Get Example source ABAP code based on a different SAP table
SELECT>, FROM hierarchy> ABAP_SYNTAX ... cds_hierarchy>
$| HIERARCHY( ... )>
$| cte_hierarchy>>
What does it do?
Specifies an SQL hierarchy> as a data source in an AB_SQL query.
The following can be maintained:
A CDS hierarchy> cds_hierarchy>>
The hierarchy generator> HIERARCHY>>
A CTE hierarchy> cte_hierarchy>>
An SQL hierarchy can be specified in the following places:
As a data source data_source>> in an AB_SQL query>.
As the source of a hierarchy navigator>
As the source of the hierarchy generator HIERARCHY>>
An SQL hierarchy is a tabular set of rows that represent the hierarchy nodes>.
A CDS hierarchy and the hierarchy generator HIERARCHY> create their result set from the data source defined for them based on a parent-child relationship> itself defined in a hierarchy association>.
A CTE hierarchy> represents the hierarchy that is 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 an SQL hierarchy are composed as follows:
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 exactly the components listed here.
In the case of the hierarchy generator HIERARCHY>, these are all components of the source of the SQL hierarchy.
Additional hierarchy columns>. For each hierarchy node, the hierarchy columns contain its hierarchy attributes>, which describe certain hierarchy-specific properties.
When an SQL hierarchy is used as a data source in an AB_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 result set of the query.
If *> or ...~*> is specified, hierarchy columns are not part of the result set of the query. Only the components of the source of the SQL hierarchy are respected. In this case, the hierarchy columns are also ignored by any structure or internal table created in the INTO> clause> by an inline declaration @DATA$|@FINAL(...)>.
In other clauses, hierarchy columns can be specified regardless of the SELECT> list and are evaluated accordingly.
Latest 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 an SQL hierarchy is of interest and not the technica l properties of the hierarchy nodes.
On SAP HANA databases>, the result sets of CDS hierarchies and the hierarchy generator HIERARCHY> are created using the SAP HANA hierarchy generator function HIERARCHY > and similar. For more information, see SAP HANA documentation>.
NON_V5_HINTS
ABAP_HINT_END
ABAP_EXAMPLES
The following classes demonstrate the three ways of specifying SQL hierarchies as the data source of a SELECT> statement while reading all possible hierarchy columns>.
CL_DEMO_HIERARCHY_TREE>>
CL_DEMO_HIERARCHY_PARENT_CHILD>>
ABAP_EXAMPLE_END