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

CL_SALV_TREE key node problem

MarcinPciak
Active Contributor
0 Likes
1,449

Hi,

I am strugling with class cl_salv_tree. I want to build a tree based on entries from a table. Each entry should be related to its supernode as a child (so we had same number of nodes as number of rows in table).

I have the following code:


DATA: ref_nodes TYPE REF TO cl_salv_nodes,
          new_node  TYPE REF TO cl_salv_node,
          key_node  TYPE salv_de_node_key.
...

"get all nodes
ref_nodes = ref_table->get_nodes( ).

LOOP AT gt_sflight INTO wa_sflight.
    IF sy-tabix = 1.
      key_node = space.   "first entry is child of root node
    endif.

    "here my problem starts...
    TRY.
        new_node = ref_nodes->add_node(
                related_node   = key_node
                data_row       = wa_sflight
                relationship   = cl_gui_column_tree=>relat_last_child ).   "add row a child 

        "get new row's key
        key_node = new_node->get_key( ).
      CATCH cx_salv_msg .
    ENDTRY.
  ENDLOOP.

The problem is that only first entry is added to tree, hence as a result I have one node which is child of ROOT node.

I am wondering where is the error. I look through demo SALV_DEMO_TREE_SIMPLE but it seems my logic is correct here. Can you please help me to identify my bug?

Thank you

Marcin

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,128

You are not doing exact same as the demo program.

Check Subroutine SUPPLY_DATA in the program SALV_DEMO_TREE_SIMPLE. First it fills the node for the CARRID. Than it fills the node for the CONNID using the key of the CARRID and after that it fills the data with relation to the node CONNID.

You are trying to use the key generated in the previous node for the current node. So, it will generate the Tree with the each record as a child of th previous node.

Like:

ROOT

.. Record1

.... Record2

...... Record3

.......... Recordn

Regards,

Naimesh Patel

4 REPLIES 4
Read only

naimesh_patel
Active Contributor
0 Likes
1,129

You are not doing exact same as the demo program.

Check Subroutine SUPPLY_DATA in the program SALV_DEMO_TREE_SIMPLE. First it fills the node for the CARRID. Than it fills the node for the CONNID using the key of the CARRID and after that it fills the data with relation to the node CONNID.

You are trying to use the key generated in the previous node for the current node. So, it will generate the Tree with the each record as a child of th previous node.

Like:

ROOT

.. Record1

.... Record2

...... Record3

.......... Recordn

Regards,

Naimesh Patel

Read only

0 Likes
1,128

Hi Namesh,

Yes, you are right, but I want to achieve excatly what you shaped in your diagram: each new entry shoud be a child of previous node (I know strange case but this is how I want it to work).

The problem is that only first entry is added to the tree (when key_node = space). Later when key_node stores new entry (of the previous node) it is not added anymore. As a result I have:

Record1

without further substucture.

Moreover get_node method returns key of newly created node, so it seems ok as far as the logic is concerned. Any clues?

Thanks

Marcin

Read only

0 Likes
1,128

Oh ok...

I tried by copying the SALV_DEMO_TREE_SIMPLE to Z report and changed the logic in the SUPPLY_DATA and it gave me what you are trying to achieve.


  loop at lt_outtab into ls_data.

    IF sy-tabix = 1.
      l_last_key = space.   "first entry is child of root node
    endif.

    perform add_complete_line using  ls_data
                                     l_last_key
                            changing l_last_key.
  endloop.

I am not sure, how much deep hierarchy we could have. If you have much data than it would be a good idea to do it like this.

Regards,

Naimesh Patel

Read only

MarcinPciak
Active Contributor
0 Likes
1,128

Hehe funny situation, or rather stupid one.

The tree was populated right, but all I had to do was optimizing width of header line (lr_columns->set_optimize( gc_true )), as I couldn't see hierarchy column which was there, but hidden;)

Of course Naimesh you helped me a lot. I copied standard program and compared it to mine, thus answering my query.

Thank you and regards

Marcin