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: 

How can I sort nodes of a CL_GUI_SIMPLE_TREE tree?

Former Member
0 Kudos
733

Hi,

after a lot of unsatisfying searching I´ll take the chance to open a new thread. I have already implemented a tree by using the CL_GUI_SIMPLE_TREE class. The main nodes of the tree represent material-numbers.

Every material-number has some sub-nodes. My concern is to sort the main nodes ascending. But how can I realize that.

- Material1

|-Subkategorie1

|-Subkategorie2

- Material2

...

I hope i described my problem understandable enought. If anyone has an idea please let me know.

Thanks a lot

2 REPLIES 2

Former Member
0 Kudos
166

Hi,

Please check the program BCALV_DND_02 and also please do check this link

I don't know whether we can post this links in SCN if it cannot be posted then please delete it.

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/how-to-put-different-icons-at-every-nod...

http://www.sapfans.com/forums/viewtopic.php?f=13&t=103417&start=60

This might help you.

former_member194669
Active Contributor
0 Kudos
166

Check this sample code



  create object g_tree
    exporting
      parent              = g_custom_container
      node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single
    exceptions
      lifetime_error              = 1
      cntl_system_error           = 2
      create_error                = 3
      failed                      = 4
      illegal_node_selection_mode = 5.
  if sy-subrc <> 0.
    message a000.
  endif.

* define the events which will be passed to the backend
  ....
  ....
  ....
  call method g_tree->set_registered_events
  ....
  ....

* assign event handlers in the application class to each desired event
  set handler g_application->handle_node_double_click for g_tree.


* Sort Nodes

  sort g_prog_table by komp_name.

  node-node_key = 'Root'.              

  clear node-relatkey.      " Special case: A root node has no parent
  clear node-relatship.                " node.

  node-hidden = ' '.                   " The node is visible,
  node-disabled = ' '.                 " selectable,
  node-isfolder = 'X'.                 " a folder.
  clear node-n_image.       " Folder-/ Leaf-Symbol in state "closed":
                                       " use default.
  clear node-exp_image.     " Folder-/ Leaf-Symbol in state "open":
                                       " use default
  clear node-expander.                 " see below.
  node-text = text-001.
  append node to g_node_table.

  loop at g_prog_table into g_wa_prog_table.

*   Insert nodes
    clear node.
    node-node_key = g_wa_prog_table-key.
    node-relatkey = 'Root'.
    node-relatship = cl_gui_simple_tree=>relat_last_child.
    node-n_image = '@GV@'.
    node-expander = ' '.
    node-text = g_wa_prog_table-komp_name.
    append node to node_table.

  endloop.