cancel
Showing results for 
Search instead for 
Did you mean: 

Get Child nodes of tree

Former Member
0 Kudos

Hi everybody,

I have a WD Tree based on a recursive node in the context.

On the treeNoteType is have implemented the event "onLoadChildren".

DATA lo_el_tree_merkmal TYPE REF TO if_wd_context_element.
CALL METHOD wdevent->get_context_element
  EXPORTING
    name   = 'CONTEXT_ELEMENT'
  receiving
    value  = lo_el_tree_merkmal
    .

This shows me the node I have opened in the UI.

How can I get the childs of this node?

Thanks to all answers.

Dirk

Accepted Solutions (1)

Accepted Solutions (1)

ChrisPaine
Active Contributor
0 Kudos

Hi Dirk,

you have a reference to the node selected,

so if you have already created the subnode, then


data: lo_subnode type ref to if_wd_context_node.
lo_subnode = lo_el_tree_merkmal->get_child_node( wdctx_subnode ).

then to get the list of elements:


data: lt_elements type WDR_CONTEXT_ELEMENT_SET,
         lo_subnode_element type ref to if_wd_context_element.

lt_elements = lo_subnode->get_elements( ).

and then you could loop at it and do whatever you needed.


loop at lt_elements into lo_subnode_element.
*blah
endloop.

If you need to create the new elements, I think that others have provided this code,

Good luck!

Chris

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Chris,

perfect. This was the solution. 10 points to you!

Former Member
0 Kudos

In the OnLoadChildren action, use the below code.

* create the child nodes
  create_node(
    EXPORTING
      cur_element = context_element
      parent_key  = parent_key ).

where parent_key is the parameter that you are gonna pass.

You can decide on whether to display the child as a node or as an item. ( which means if there will be any child node under that or if that will be the last item )

If the node doesn't have any child under it, use the below code.

DATA: lr_cur_element TYPE REF TO if_wd_context_element.

  lr_cur_element = node->create_element( ).
  lr_cur_element->set_attribute( name = 'NAME' value = value1 ).
  lr_cur_element->set_attribute( name = 'NAME2' value = value2 ).


  node->bind_element( new_item = lr_cur_element set_initial_elements
= abap_false ).

else

DATA: lr_cur_element TYPE REF TO if_wd_context_element.

  lr_cur_element = cur_node->create_element( ).
  lr_cur_element->set_attribute( name = 'NAME' value = value1 ).
  lr_cur_element->set_attribute( name = 'NAME1' value = value2 ).

  cur_node->bind_element( new_item = lr_cur_element
                          set_initial_elements = abap_false ).

Former Member
0 Kudos

Hello Dirk,

you could use "if_wd_context_node" interface and use the method "get_child_node" or "get_child_nodes".

you need to pass the reference of the root node to the variable(type red) of type "if_wd_context_node".

Thanks and Regards

Anurag Chopra