Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to use cl_gui_alv_tree->add_node correctly?

Former Member
0 Kudos
1,061

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?

 

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Kudos
1,024

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").

Read only

0 Kudos
1,000

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.

Read only

0 Kudos
993

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.

Read only

0 Kudos
914

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( ... )".

Read only

0 Kudos
906

Possibly use the ABAP Cleaner with SE80 via Ctrl+C/Ctrl+V SAP/abap-cleaner: ABAP cleaner.