\n1<\/span><\/td>\n | 10,0000000024;6,000000<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 1<\/span><\/td>\n | 1<\/span><\/td>\n | 11<\/span><\/td>\n<\/tr>\n\n2<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000067;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 2<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n3<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000061;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 3<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n4<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000060;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 4<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n5<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000063;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 5<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n6<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000064;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 6<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n7<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000065;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 7<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n8<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000066;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 8<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n9<\/span><\/td>\n | 10,0000000025;6,000000<\/span><\/td>\n | 10,0000000068;6,000000<\/span><\/td>\n | 2<\/span><\/td>\n | 9<\/span><\/td>\n | 3<\/span><\/td>\n<\/tr>\n\n10<\/span><\/td>\n | 10,0000000068;6,000000<\/span><\/td>\n | 10,0000000069;6,000000<\/span><\/td>\n | 3<\/span><\/td>\n | 10<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\n11<\/span><\/td>\n | 10,0000000068;6,000000<\/span><\/td>\n | 10,0000000070;6,000000<\/span><\/td>\n | 3<\/span><\/td>\n | 11<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n We get all relationships between nodes, starting from contract 24. What’s great all children are listed out in the node column, so our goal has been achieved. Let’s dig deeper into it however and take a look at hierarchy specific fields which may help us with traversing a hierarchy. Below pictures explain two of them:<\/span><\/p>\n<\/p>\n <\/p>\n HIERARCHY_DESCENDANTS<\/strong><\/h3>\nIn this example however we are going to consume our CDS hierarchy directly.<\/span><\/p>\n<\/p>\n Result:<\/span><\/p>\n\n\n\nINDEX<\/td>\n | PRECEDINGDOCUMENT<\/td>\n | PRECEDINGITEM<\/td>\n | SUBSEQUENTDOCUMENT<\/td>\n | SUBSEQUENTITEM<\/td>\n | PARENTNODE<\/td>\n | CHILDNODE<\/td>\n | HIERARCHYISORPHAN<\/td>\n | HIERARCHYLEVEL<\/td>\n | HIERARCHYRANK<\/td>\n | HIERARCHYPARENTRANK<\/td>\n | HIERARCHYTREESIZE<\/td>\n<\/tr>\n | \n1<\/td>\n | 0000000024<\/td>\n | 0<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 10,0000000024;6,000000<\/td>\n | 10,0000000025;6,000000<\/td>\n | 1<\/td>\n | 1<\/td>\n | 2<\/td>\n | 0<\/td>\n | 11<\/td>\n<\/tr>\n | \n2<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000067<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000067;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 3<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n3<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000061<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000061;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 4<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n4<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000060<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000060;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 5<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n5<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000063<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000063;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 6<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n6<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000064<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000064;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 7<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n7<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000065<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000065;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 8<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n8<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000066<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000066;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 9<\/td>\n | 2<\/td>\n | 1<\/td>\n<\/tr>\n | \n9<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 0000000068<\/td>\n | 0<\/td>\n | 10,0000000025;6,000000<\/td>\n | 10,0000000068;6,000000<\/td>\n | 1<\/td>\n | 2<\/td>\n | 10<\/td>\n | 2<\/td>\n | 3<\/td>\n<\/tr>\n | \n10<\/td>\n | 0000000068<\/td>\n | 0<\/td>\n | 0000000069<\/td>\n | 0<\/td>\n | 10,0000000068;6,000000<\/td>\n | 10,0000000069;6,000000<\/td>\n | 1<\/td>\n | 3<\/td>\n | 11<\/td>\n | 10<\/td>\n | 1<\/td>\n<\/tr>\n | \n11<\/td>\n | 0000000068<\/td>\n | 0<\/td>\n | 0000000070<\/td>\n | 0<\/td>\n | 10,0000000068;6,000000<\/td>\n | 10,0000000070;6,000000<\/td>\n | 1<\/td>\n | 3<\/td>\n | 12<\/td>\n | 10<\/td>\n | 1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n I used * sign in select, therefore, all fields from defined earlier CDS hierarchy were selected. Notice that in this case Z_VBFA_HIERARCHY is consumed, not Z_VBFA.<\/span><\/p>\n <\/p>\n HIERARCHY_ANCESTORS<\/strong><\/h3>\nThis function will return the ancestors of a given node.<\/span><\/p>\n<\/p>\n Result:<\/p>\n \n\n\nINDEX<\/td>\n | PRECEDINGDOCUMENT<\/td>\n | PRECEDINGITEM<\/td>\n | SUBSEQUENTDOCUMENT<\/td>\n | SUBSEQUENTITEM<\/td>\n | PARENTNODE<\/td>\n | CHILDNODE<\/td>\n | HIERARCHYISORPHAN<\/td>\n | HIERARCHYLEVEL<\/td>\n | HIERARCHYRANK<\/td>\n | HIERARCHYPARENTRANK<\/td>\n | HIERARCHYTREESIZE<\/td>\n<\/tr>\n | \n1<\/td>\n | 0000000024<\/td>\n | 0<\/td>\n | 0000000025<\/td>\n | 0<\/td>\n | 10,0000000024;6,000000<\/td>\n | 10,0000000025;6,000000<\/td>\n | 1<\/td>\n | 1<\/td>\n | 2<\/td>\n | 0<\/td>\n | 11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n I have added orphans root annotation therefore one relationship in the hierarchy is displayed.<\/span><\/p>\nAlternative syntax<\/strong><\/h3>\nYou can combine HIERARCHY and HIERARCHY_DESCENDANTS\/HIERARCHY_ANCESTORS:<\/span><\/p>\n<\/p>\n <\/p>\n It will dynamically return hierarchy and apply HIERARCHY_DESCENDANTS on the result. Notice that we are not using Z_VBFA_HIERARCHY here but Z_VBFA. The result will be exactly the same as in HIERARCHY_DESCENDANTS.<\/span><\/p>\nSummary<\/strong><\/h3>\nI hope you can see the advantage of such solution. With few annotations and one select, we can extract the whole tree. With additional parameters like hierarchy_rank etc. it is incredibly easy to traverse through the whole structure. You can even select all other business data and have them all with one simple select. When possible avoid writing complex code!<\/span><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" The problem Recently I have faced a quite interesting problem. There is a concept of something like ‘frame contract’. It means that out of this document many others of the same type (or not necessairely) can be created. Let’s take a look at VBFA table (Sales Document Flow). I am interested only in subsequent Sales […]<\/p>\n","protected":false},"author":17,"featured_media":3867,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":""},"categories":[1],"tags":[7,82],"acf":[],"yoast_head":"\n ABAP CDS recursive association using hierarchy - INT4<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t\n | | | | | | | | | | | | |