Wenn ich deinen Aufbau richtig verstehe suchts du sowas etwas:JetGum hat geschrieben:Ich denke es wird wohl in irgend einer Form ein rekursiver Aufruf notwendig sein, um das ganze möglichst generisch zu halten.
Code: Alles auswählen.
REPORT ztest_tree.
TYPES: t_c TYPE c LENGTH 4,
BEGIN OF ts_tree,
nummer TYPE t_c,
vornum TYPE t_c,
level TYPE i,
END OF ts_tree,
tt_tree TYPE TABLE OF ts_tree.
DATA: gt_tree TYPE tt_tree,
gw_tree TYPE ts_tree.
START-OF-SELECTION.
* Interne Tabelle füllen
gw_tree-nummer = '1000'.
gw_tree-level = '1'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1101'.
gw_tree-vornum = '1000'.
gw_tree-level = '2'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1111'.
gw_tree-vornum = '1101'.
gw_tree-level = '3'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1121'.
gw_tree-vornum = '1111'.
gw_tree-level = '4'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1122'.
gw_tree-vornum = '1111'.
gw_tree-level = '4'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1123'.
gw_tree-vornum = '1111'.
gw_tree-level = '4'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1112'.
gw_tree-vornum = '1102'.
gw_tree-level = '3'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1102'.
gw_tree-vornum = '1000'.
gw_tree-level = '2'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '1103'.
gw_tree-vornum = '1000'.
gw_tree-level = '2'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '2000'.
gw_tree-level = '1'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '2100'.
gw_tree-vornum = '2000'.
gw_tree-level = '2'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '2100'.
gw_tree-vornum = '2000'.
gw_tree-level = '2'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
gw_tree-nummer = '3000'.
gw_tree-level = '1'.
APPEND gw_tree TO gt_tree. CLEAR gw_tree.
* Root:
WRITE: / 'Nummer', 'VorNummer', 'Level'.
* 1. Level
LOOP AT gt_tree INTO gw_tree WHERE level = '1'.
WRITE: / gw_tree-nummer, gw_tree-vornum, gw_tree-level.
* Nächstes Level mittels Rekursion ermitteln
PERFORM get_next_level USING gw_tree-nummer
gw_tree-level
gt_tree.
ENDLOOP.
FORM get_next_level USING p_nummer TYPE t_c
p_level TYPE i
pt_tree TYPE tt_tree.
DATA: lw_tree TYPE ts_tree,
l_level TYPE i,
l_einschub TYPE string.
CLEAR: l_level, l_einschub.
* Einschub aufbauen
l_level = p_level + 1.
DO p_level TIMES.
CONCATENATE l_einschub ` ` INTO l_einschub.
ENDDO.
LOOP AT pt_tree INTO lw_tree WHERE vornum = p_nummer
AND level = l_level.
WRITE: / l_einschub NO-GAP, lw_tree-nummer, lw_tree-vornum, lw_tree-level.
* Nächstes Level mittels Rekursion ermitteln
PERFORM get_next_level USING lw_tree-nummer
lw_tree-level
pt_tree.
ENDLOOP.
ENDFORM. "get_next_level
Code: Alles auswählen.
Nummer VorNummer Level
1000 1
1101 1000 2
1111 1101 3
1121 1111 4
1122 1111 4
1123 1111 4
1102 1000 2
1112 1102 3
1103 1000 2
2000 1
2100 2000 2
2100 2000 2
3000 1