How to use cl_gui_alv_tree->add_node correctly?

Hi, experts.
How to use cl_gui_alv_tree->add_node correctly?
For example i have 10 nodes to add and then use ‘for event item_double_click of cl_gui_alv_tree’ and display different ALV, with different fieldcatalogs and different tables.
Now i use this logic.

 

ls_layo-exp_image =’@FQ@’.
ls_layo-n_image = ‘@FQ@’.
gs_fieldcat-name = lines( tab_of_vblen_status ).
call method obj_tree->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ‘Загрузка на портал’
is_node_layout = ls_layo
is_outtab_line = gs_fieldcat
importing
e_new_node_key = p_node_key.
methods : item_double_click
for event item_double_click of cl_gui_alv_tree
importing node_key fieldname.

 

 

 

method item_double_click.

w_variant-report = sy-repid.
ls_layout-cwidth_opt = ‘X’.
ls_layout-grid_title = ”.
sel_node_key = node_key.
case node_key.
when text-001 or text-002 or text-005 or text-004.
init=>init_container( ).
ls_layout-sel_mode = ‘A’.
init=>init_fieldcat( ).
init=>create_alv_and_display( ).

when text-003 or text-006 or text-007 or text-008 or text-009.
init=>init_container( ).
ls_layout-sel_mode = ‘X’.
init=>init_fieldcat( ).
init=>create_alv_and_display( ).
endcase.

 

 

But what if in future i would be needed to add additional node at position ‘5’, i would need to rewrite all the logic for nodes from 5 to end.
How to do it correctly? I don’t want to do it. How forseen it, to not change all the logic?What i can check, when node is doubleclicked?

 

Scroll to Top