cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize the element of subnode in the context?

former_member201541
Participant
0 Kudos

Hi,

I have a requirement wherein I want to initialize the element of subnode in the context? I know how initialize a element of a normal node.

Please help fast.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Ajinkya,

To get the element of subnode, you should know the element index of parent node and use the method PATH_GET_NODE of interface IF_WD_CONTEXT_NODE.

Please refer below links:

Reference Path to Deeper Context Nodes - Web Dynpro for ABAP - SAP Library

Other way, get child node

     data lo_parent_node type ref to if_wd_context_node.

     data lo_child_node type ref to if_wd_context_node.

     data lo_element type ref to if_wd_context_element.


     lo_parent_node = wd_context->get_child_node( name = 'MY_PARENT_NODE' ).

     " get the index of node which you are willing

     lo_element = lo_parent_node->get_element( 2 ). " sub node of second line

    

     lo_child_node = lo_element->get_child_node( name = 'MY_CHILD_NODE' ).


     LO_CHILD_NODE->INVALIDATE( ).   


Also, you can use supply function to set the value/initialize subnode based on parent node's element .

Please refer the below link

Supply function with singleton concept | Team ABAP

Hope this helps you.

Regards,

Rama

former_member201541
Participant
0 Kudos

Thanks,

But by this I'm able to initialize only 1st sub node i.e lo_element = lo_parent_node->get_element( 1 ).

If I give lo_element = lo_parent_node->get_element( 2 ) I'm getting error "Null Object Reference not possible".


I want to initialize first four sub nodes of the parent node.

Please help.



ramakrishnappa
Active Contributor
0 Kudos

Hi Ajinkya,

Then, get the data of parent node and loop over the entries and based on sy-tabx, invalidate the subnodes

Please refer the below thread.

Hope this helps you.

Regards,

Rama

Answers (1)

Answers (1)

harsha_jalakam
Active Contributor
0 Kudos

Hi Ajinkya,

Supply functions can be used in this case for initializing the sub-node elements, to the corresponding parent element. Since at runtime we can not decide how many elements does exists in the parent node,  it is better not to initialize the elements through sa-tabix values. Or if the number of elements in both parent and the child node are fixed then ,  manual initialization could be followed.

Regards,

Harsha