Application Development 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: 

SAP Tree order problem

Former Member
0 Kudos

Hi experts,

I have a SAP Tree made using the class cl_simple_tree_model.

I add nodes to it calling the method add_node.

That is working, but the order of nodes of level one has been inverted. That is, the first node that is added appear in the last position of tree.

That occurs only with the nodes of level one.

How can I solve this?

Regards,

Charles

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

l_nodekey = object->nodekey( ).

l_node_name = object->name( ).

call method object_tree->add_node

exporting

node_key = l_nodekey

relative_node_key = root_node_title

isfolder = abap_false

text = l_node_name.

l_object_ref_wa-name = l_nodekey.

l_object_ref_wa-reference = object.

append l_object_ref_wa into table object_table.

are you using Append or Insert.

Use APPEND , instead of Insert. Append will add the nodes one by one. But in your case insert may be adding at the first. i m not sure. If you can show the add_node logic then i can tell you.

Regards

Vijay Babu Dudla

5 REPLIES 5

former_member188685
Active Contributor
0 Kudos

l_nodekey = object->nodekey( ).

l_node_name = object->name( ).

call method object_tree->add_node

exporting

node_key = l_nodekey

relative_node_key = root_node_title

isfolder = abap_false

text = l_node_name.

l_object_ref_wa-name = l_nodekey.

l_object_ref_wa-reference = object.

append l_object_ref_wa into table object_table.

are you using Append or Insert.

Use APPEND , instead of Insert. Append will add the nodes one by one. But in your case insert may be adding at the first. i m not sure. If you can show the add_node logic then i can tell you.

Regards

Vijay Babu Dudla

0 Kudos

Hi Vijay,

I´m using append. Although I´m sure that if I was using insert the result would be the same.

Here is the logic:


    IF v_relative_node_key = 0.
      CALL METHOD g_tree->add_node
        EXPORTING
          node_key = l_node_key
          text     = l_text
          isfolder = l_isfolder
        EXCEPTIONS
          OTHERS   = 1.
    ELSE.
      CALL METHOD g_tree->add_node
        EXPORTING
          node_key          = l_node_key
          text              = l_text
          relative_node_key = l_relative_node_key
          relationship      = l_relationship
          isfolder          = l_isfolder
        EXCEPTIONS
          OTHERS            = 1.
    ENDIF.

0 Kudos

Sorry - we clearly cross-posted.

In your method call for the first level , you do not supply the parameter relationship. This means that its default value of zero is used. However, zero is also the value of the constant cl_simple_tree_model=>relat_first_child, which means that the last node inserted is at the top of the branch.

To append a new node to the bottom of the current level, your method call should include the parameter

relationship = cl_simple_tree_model=>relat_last_sibling.

Hope this helps

Jon.

0 Kudos

Thanks Jonathan, that solve my problem.

Former Member
0 Kudos

Charles,

can you supply a code extract?

Regards

Jon.