do you know a efficient method to generate a parent-child hierarchy from a table without parent node IDs. The parent child relationship should be switchable. All of this should be done in ABAP.
example data:
Color producer weight Airplane(key)
green CompanyA 330 A350
green CompanyA 222 A320
green CompanyB 222 B450
yellow CompanyA 330 H450
I want generate a child parent relationship based on this rows: producer weight Airplane and ignore color. Then i will change it and use: Color weight Airplane and ignore producer
At the end i need a result looks like for "producer weight Airplane"
CompanyA CompanyB
330 222 222
A350 A320 B450
H450
in a internal table it should look like this at the end
ID attribute value H_level parentID
1 producer CompanyA 1
2 weight 330 2 1
3 airplane A350 3 2
.....
does anyone have a good efficient idea? Thanks a lot.
Here is a simple tree-building algorithm that does what you need.
Note that this algorithm is not optimized in terms of performance. If you manage large amounts of data, you may want to revise some aspects, for example use SORTED or HASHED rather than STANDARD tables to improve the lookup READ TABLEs.
The algorithm is also not refactored for optimum code style. For example, clean code suggests we may want to extract a couple of methods to improve readability.
Verified with the following unit test. It represents the example you gave: