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

set relation in cl_simple_tree_model for existing node

EnnoWulff
Active Contributor
0 Likes
1,504

Hi there!

I am struggeling with inserting a node at a specific position using the cl_simple_tree_model.

I build up a tree structure. No big deal.

Let's say I display customer orders and the order items as child nodes.

Then the user changes the customer order and changes, adds or deletes items. I don't want to make fuzz about every single item and check if it's still there, has been deleted or added or if the text has changed or status has changed and so on.

My idea was to simply delete the node of the customer order and rebuild it completely. That's also possible and I can add the new nodes using method ADD_NODES and ADD_ITEMS.

BUT: I can only add the nodes using the relationships

  • First/ Next/ Last child
  • First/ Next/ Last sibling

So an order "in the middle" will be placed at the top (first child) or bottom (last child) of the structure.

How can I place the "updated" node at exactly the same position as before?

thanks for any idea!

Enno

1 ACCEPTED SOLUTION
Read only

EnnoWulff
Active Contributor
0 Likes
1,229

It's so easy... *head->table*

Method ADD_NODE and ADD_NODES have the importing parameter "RELATIVE_NODE_KEY".

If you want to "Update" the current node you just have to add the updated nodes with RELATIVE_NODE_KEY = new_node_key and RELATIONSHIP = next_sibling or prev_sibling. Then you delete the old node.

If you have unique node-keys, like order number, or material number, then you first have to check NODE_GET_PREV_SIBLING, then delete the old node and afterwards add the new nodes with RELATIVE_NODE_KEY = prev_sibling_of_old_node and RELATIONSHIP = next_sibling.

If there is no previous sibling, then you have to find out the parent NODE_GET_PARENT and set relationship to first_child.

4 REPLIES 4
Read only

Domi
Active Contributor
1,229

Hi

I always rebuild the tree completely on any change, so I only have to deal with inserts, updates, deletes, sortorder, ... in my ITab(s) and dont really care about this in Tree build methods.

And since the tree is UI (mostly with user interaction) I try to keep it short and readable and therefore had nevere any performance issues regarding tree rebuild or GUI transfer!

If anyone has a better (delta) solution - I would use it!

kr

Domi

Read only

EnnoWulff
Active Contributor
0 Likes
1,229

Thanks Domi! I would like to avoid a complete rebuild as we have thousands of nodes in the view... 😞

I will try to just update the "order node", delete all child nodes and add only the child nodes.

Read only

Domi
Active Contributor
1,229

Hi

Yea, I do understand - that's why I try to keep the tree "short and readable"

User only need 5, 10 maybe 20 orders on one screen, so you could add some filter or search criteria?

I often use a hyperlink in the 1st root item to add an filter via a popup.

regards

Domi

Read only

EnnoWulff
Active Contributor
0 Likes
1,230

It's so easy... *head->table*

Method ADD_NODE and ADD_NODES have the importing parameter "RELATIVE_NODE_KEY".

If you want to "Update" the current node you just have to add the updated nodes with RELATIVE_NODE_KEY = new_node_key and RELATIONSHIP = next_sibling or prev_sibling. Then you delete the old node.

If you have unique node-keys, like order number, or material number, then you first have to check NODE_GET_PREV_SIBLING, then delete the old node and afterwards add the new nodes with RELATIVE_NODE_KEY = prev_sibling_of_old_node and RELATIONSHIP = next_sibling.

If there is no previous sibling, then you have to find out the parent NODE_GET_PARENT and set relationship to first_child.