2024 Oct 01 2:27 PM
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?
2024 Oct 01 3:39 PM
Why do you say you need to "rewrite all"? If you add one node, you just have to add one "OR 'new node key'", it's not "rewrite all".
Wrong usage: don't use text symbols for node_key, because the text is not to be translated. Instead, use a constant.
This next line should be a text symbol because it can be potentially translated, so you should append the text symbol number you want:
i_node_text = 'Загрузка на портал'(001)
Obsolete: "call method obj_tree->add_node" (instead, use "obj_tree->add_node").
2024 Oct 01 4:42 PM - edited 2024 Oct 01 4:45 PM
Let's imagine i have 10 nodes in mine tree. And if the node is even - i'm going to show one alv, whe it's odd - the other.
And i need to add node at the fifth position. The node's from 5 to 10 - will change their 'node_key' to 6-11.
5 become 6, 6 become 7 and so on.
And part of code, which was setting which (alv, toolbar, fieldcat and so on ) would be shown in a screen is not works anymore, cause it 'node_key' is change, for the elements from 5 to 10 -> 6-11.
Now i'm checking only 'node_key' for the logic and then decide which alv i would show.
'node_key' is char12 with the numc value in it.And it's filled automatically after 'add_node' method.
2024 Oct 01 5:05 PM
Thanks, I understand. When building your tree (ADD_NODE), build a new internal table to contain the "ALV Grid ID" to use for each node key. When ITEM_DOUBLE_CLICK is called, access this internal table to retrieve the "ALV Grid ID" to display corresponding to the node key.
2024 Oct 02 2:06 PM
A note to <<Obsolete: "call method obj_tree->add_node" (instead, use "obj_tree->add_node").>>:
Pretty printer in windows gui works good with method calls like "call method obj_tree->add_node". It does not work with calls like "obj_tree->add_node( ... )".
2024 Oct 02 4:18 PM
Possibly use the ABAP Cleaner with SE80 via Ctrl+C/Ctrl+V SAP/abap-cleaner: ABAP cleaner.