Get Example source ABAP code based on a different SAP table
• DEFINE HIERARCHY ABAP_CDS_DDL_STATEMENT • SOURCE ABAP_CDS_DEFINE_HIERA • AS PARENT CHILD HIERARCHY ABAP_CDS_DEFINE_HIERA • CHILD TO PARENT ASSOCIATION ABAP_CDS_DEFINE_HIERA • DIRECTORY FILTER BY ABAP_CDS_DEFINE_HIERA • START WHERE ABAP_CDS_DEFINE_HIERA • SIBLINGS ORDER BY ABAP_CDS_DEFINE_HIERA • ASCENDING ABAP_CDS_DEFINE_HIERA • DESCENDING ABAP_CDS_DEFINE_HIERA • DEPTH ABAP_CDS_DEFINE_HIERA • NODETYPE ABAP_CDS_DEFINE_HIERA • MULTIPLE PARENTS ALLOWED ABAP_CDS_DEFINE_HIERA • MULTIPLE PARENTS NOT ALLOWED ABAP_CDS_DEFINE_HIERA • MULTIPLE PARENTS LEAVES ONLY ABAP_CDS_DEFINE_HIERA • ORPHANS ERROR ABAP_CDS_DEFINE_HIERA • ORPHANS IGNORE ABAP_CDS_DEFINE_HIERA • ORPHANS ROOT ABAP_CDS_DEFINE_HIERA • CYCLES ERROR ABAP_CDS_DEFINE_HIERA • LOAD BULK ABAP_CDS_DEFINE_HIERA • LOAD INCREMENTAL ABAP_CDS_DEFINE_HIERA • CYCLES BREAKUP ABAP_CDS_DEFINE_HIERA • GENERATE SPANTREE ABAP_CDS_DEFINE_HIERA • PERIOD FROM TO ABAP_CDS_DEFINE_HIERA • VALID FROM TO ABAP_CDS_DEFINE_HIERA • CACHE ON ABAP_CDS_DEFINE_HIERA • CACHE OFF ABAP_CDS_DEFINE_HIERA • CACHE FORCE ABAP_CDS_DEFINE_HIERA
ABAP_CDS_DDL - DEFINE HIERARCHY>
ABAP_SYNTAX $[@entity_annot1>$] $[@entity_annot2>$] ... $[@hierarchy_annot1>$] $[@hierarchy_annot2>$] ... $[DEFINE$] HIERARCHY hierarchy $[parameter_list>$] AS PARENT CHILD HIERARCHY( SOURCE cds_view CHILD TO PARENT ASSOCIATION _hierarchy_assoc $[PERIOD FROM field1 TO field2 VALID FROM from TO to$] $[DIRECTORY _directory_assoc FILTER BY cds_cond$] $[START WHERE cds_cond$] SIBLINGS ORDER BY field1 $[ASCENDING$|DESCENDING$]$[, field2 $[ASCENDING$|DESCENDING$], ...$] $[DEPTH depth$] $[NODETYPE node_type$] $[LOAD BULK$|INCREMENTAL$|load_option$] $[MULTIPLE PARENTS ${NOT ALLOWED$}$|LEAVES$|ALLOWED$] $[ORPHANS IGNORE$|ERROR$|ROOT$] $[CYCLES ERROR$|BREAKUP$] $[GENERATE SPANTREE$] $[CACHE ON$|OFF$|FORCE$]) { element_list> }>
ABAP Addition 1 ... SOURCE cds_view> 2 ... CHILD TO PARENT ASSOCIATION _hierarchy_assoc> 3 ... PERIOD FROM field1 TO field2 VALID FROM from TO to> 4 ... DIRECTORY _directory_assoc FILTER BY cds_cond> 5 ... START WHERE cds_cond> 6 ... SIBLINGS ORDER BY field1 $[ASCENDING$|DESCENDING$], ...> 7 ... DEPTH depth> 8 ... NODETYPE node_type> 9 ... LOAD BULK$|INCREMENTAL$|load_option> 10 ... MULTIPLE PARENTS ${NOT ALLOWED$}$|${LEAVES ONLY$}$|ALLOWED > 11 ... ORPHANS IGNORE$|ERROR$|ROOT> 12 ... CYCLES ERROR$|BREAKUP> 13 ... GENERATE SPANTREE> 14 ... CACHE ON$|OFF$|FORCE>
What does it do? Defines a CDS entity> hierarchy> as a CDS hierarchy> in the CDS DDL>. A CDS hierarchy has a tabular result set whose rows construct parent-child relationships >. When a CDS hierarchy is accessed as the data source of a AB_SQL > query, it is handled like an SQL hierarchy> in which additional hierarchy columns> can be selected.
@entity_annot>> and @hierarchy_annot>> can be used to specify optional annotations> for the CDS hierarchy.
parameter_list>> is used to declare a list of optional input parameters for the CDS hierarchy.
element_list>> is used to declare the elements of the CDS hierarchy. The additions in parentheses after AS PARENT CHILD HIERARCHY> define the way the hierarchy is created:
SOURCE> must be followed by a ABAP_CDS_V2_VIEW > or a ABAP_CDS_V1_VIEW > cds_view> as the source of the hierarchy.
CHILD TO PARENT ASSOCIATION> must be followed by a hierarchy association> _hierarchy_assoc> exposed by the source cds_view>. The hierarchy association must be a self-association> where the association source> and association target> must be the source cds_view>. The ON> condition of the hierarchy association defines the parent-child relationships > between the hierarchy nodes>.
START WHERE> can be followed by a start condition that defines root nodes> for the root node set> of the hierarchy. The hierarchy consists of the root nodes of the root node set and their descendant nodes>. If START WHERE > is not specified, the root node set implicitly consists of all rows where the column that contains the parent node> (as defined by the hierarchy association) is initial. All other additions define further properties of the hierarchy. The rows of the tabular result set of the CDS hierarchy are the hierarchy nodes> of the new hierarchy but without its hierarchy columns>. The name of a CDS hierarchy is in the namespace of all global types> of an AS ABAP.
Latest notes:
The syntax and functions of a CDS hierarchy overlap to a large extent with the hierarchy generator> HIERARCHY>> in AB_SQL