cancel
Showing results for 
Search instead for 
Did you mean: 

Context node NOT child of root:, How to get addressability to its elements?

Former Member
0 Kudos

In the WDA class I'm taking right now (NET310), it shows you how to get the child node of the root context, find the lead selection among its elements, and then set or get attributes of this element.

But suppose you have a context hiearchy in which the root has the child A, A has the child B, and B has the child C.

Also suppose that you want to set/get some attributes of a non-initial element of C.

To "get to" an element of C, do you have to start at the root, get addressability to A, then use this to get addressability to B, and then use this to get addressability to C? (So that you can do something with an element of C.)

Or is there a way of directly obtaining addressability to an element of C, so that you don't have to "chain down" from the root?

Am I missing something here? (Probably.)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Ideally, you can just use the Webdynpro Code wizard (Ctrl + F7) on the toolbar. This wizard allows you to select the node you want to work with and automatically generates the code for it.

For eg. I had defined something like Root -> Child1 -> child2 -> child 3. I read the context node Child3, using the wizard. It generated the following piece of code for me:

DATA lo_nd_child3 TYPE REF TO if_wd_context_node.

  DATA lo_el_child3 TYPE REF TO if_wd_context_element.
  DATA ls_child3 TYPE wd_this->element_child3.

* navigate from <CONTEXT> to <CHILD3> via lead selection
  lo_nd_child3 = wd_context->path_get_node( path = `ROOT.CHILD1.CHILD2.CHILD3` ).

* @TODO handle non existant child
* IF lo_nd_child3 IS INITIAL.
* ENDIF.

* get element via lead selection
  lo_el_child3 = lo_nd_child3->get_element( ).
* @TODO handle not set lead selection
  IF lo_el_child3 IS INITIAL.
  ENDIF.

* get all declared attributes
  lo_el_child3->get_static_attributes(
    IMPORTING
      static_attributes = ls_child3 ).

Hope this helps

Regards,

Wenonah

former_member181923
Active Participant
0 Kudos

Hi Wenonah -

Thanks very much. That was a great answer for two reasons:

a) you showed what the code generator does in that situation;

b) you confirmed my suspicion that you do have to "chain downward", although you do it in one step with the path method.

Best regards

djh

Answers (0)