Update
This commit is contained in:
@@ -2,19 +2,8 @@
|
||||
|
||||
# ABAP SQL: Working with Hierarchies
|
||||
|
||||
This cheat sheet summarizes the functions ABAP SQL offers together with
|
||||
ABAP CDS for working with [hierarchical
|
||||
data](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_glosry.htm "Glossary Entry")
|
||||
that is stored in database tables. Hierarchical data in database tables
|
||||
means that lines of one or more database tables are connected by
|
||||
[parent-child
|
||||
relationships](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpcr_glosry.htm "Glossary Entry").
|
||||
There are many use cases where hierarchical data plays a role and where
|
||||
accessing information about the hierarchical relationship is important.
|
||||
For example, a common task can be to find out the descendants or
|
||||
ancestors of a given hierarchy node or to aggregate values of subtrees.
|
||||
|
||||
- [ABAP SQL: Working with Hierarchies](#abap-sql-working-with-hierarchies)
|
||||
- [Introduction](#introduction)
|
||||
- [Overview](#overview)
|
||||
- [SQL Hierarchies](#sql-hierarchies)
|
||||
- [Creating SQL Hierarchies](#creating-sql-hierarchies)
|
||||
@@ -28,6 +17,19 @@ ancestors of a given hierarchy node or to aggregate values of subtrees.
|
||||
- [Hierarchy Aggregate Navigators](#hierarchy-aggregate-navigators)
|
||||
- [More Information](#more-information)
|
||||
|
||||
## Introduction
|
||||
|
||||
This cheat sheet summarizes the functions ABAP SQL offers together with
|
||||
ABAP CDS for working with [hierarchical
|
||||
data](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_glosry.htm "Glossary Entry")
|
||||
that is stored in database tables. Hierarchical data in database tables
|
||||
means that lines of one or more database tables are connected by
|
||||
[parent-child
|
||||
relationships](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpcr_glosry.htm "Glossary Entry").
|
||||
There are many use cases where hierarchical data plays a role and where
|
||||
accessing information about the hierarchical relationship is important.
|
||||
For example, a common task can be to find out the descendants or
|
||||
ancestors of a given hierarchy node or to aggregate values of subtrees.
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -57,6 +59,8 @@ learn some additional syntax and then you can start right away.
|
||||
> **💡 Note**<br>
|
||||
> The examples in this cheat sheet are only relevant for [standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm), i. e. the unrestricted ABAP language scope. Find the artifacts used in the code snippets in your on-premise system.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
## SQL Hierarchies
|
||||
|
||||
With [SQL
|
||||
@@ -99,6 +103,8 @@ for each row. For creating a SQL hierarchy, you need the following:
|
||||
The following topics show you step-by-step how SQL hierarchies can be
|
||||
created and accessed.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
## Creating SQL Hierarchies
|
||||
|
||||
### ABAP CDS Hierarchies
|
||||
@@ -252,6 +258,8 @@ From the ABAP language point of view, CDS hierarchies are the most
|
||||
convenient way of using SQL hierarchies. Now let us turn to other ways,
|
||||
involving more ABAP, until we do not use any CDS more in the end.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### ABAP SQL Hierarchy Generator HIERARCHY
|
||||
The ABAP SQL [hierarchy
|
||||
generator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_generator_glosry.htm "Glossary Entry")
|
||||
@@ -367,6 +375,8 @@ not least we will use CTEs as hierarchies themselves. You might skip the
|
||||
following section and turn directly to the hierarchy navigators if you
|
||||
are not too interested in this syntactic gimmicks.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### ABAP CTE Hierarchies
|
||||
|
||||
A CTE that produces hierarchical data can declare itself as a SQL
|
||||
@@ -479,6 +489,8 @@ hierarchy association. Running
|
||||
`CL_DEMO_SQL_HIERARCHIES` shows that all
|
||||
assertions are fulfilled.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
## Hierarchy Navigators
|
||||
|
||||
[Hierarchy
|
||||
@@ -501,6 +513,8 @@ or a CTE hierarchy. Check the examples of the
|
||||
[documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenselect_hierarchy_navigators.htm),
|
||||
where this is also shown.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### Hierarchy Node Navigator HIERARCHY_DESCENDANTS
|
||||
|
||||
As the name says,
|
||||
@@ -536,6 +550,8 @@ distance to the respective start node. A further parameter
|
||||
`DISTANCE` - not shown here - allows you to restrict the
|
||||
distance to the respective start node.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### Hierarchy Node Navigator HIERARCHY_ANCESTORS
|
||||
|
||||
Now the other way around: ABAP SQL function
|
||||
@@ -566,6 +582,8 @@ aggregate functions or evaluating the internal result table, you can now
|
||||
easily extract further information like the number of ancestors and so
|
||||
on.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### Hierarchy Node Navigator HIERARCHY_SIBLINGS
|
||||
|
||||
Besides descendants and ancestors, hierarchy nodes also can have
|
||||
@@ -598,6 +616,8 @@ the respective start node. Running
|
||||
`CL_DEMO_SQL_HIERARCHIES`, where we start with
|
||||
a node that definitely has some siblings, shows the result.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
### Hierarchy Aggregate Navigators
|
||||
|
||||
Finally let us turn to the [hierarchy aggregate
|
||||
@@ -697,5 +717,7 @@ Running `CL_DEMO_SQL_HIERARCHIES` shows the
|
||||
result. It also shows the result of the joined data source, where you
|
||||
can check that the calculated values are correct.
|
||||
|
||||
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
|
||||
|
||||
## More Information
|
||||
For the complete reference documentation about SQL hierarchies, see [`SELECT, FROM hierarchy_data`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenselect_hierarchy_data.htm).
|
||||
|
||||
Reference in New Issue
Block a user