Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Read node as table operation using code wizard

This document explains the code generated using the code wizard for reading the node as table operation. This explanation in the document should also explain you how code is generated using the code wizard for operation on context node.

Predefined Object references:

 

WD_THIS – Instance for the current controller.

WD_CONTEXT – Instance for the Root context node.

 

Let us assume the name of the context node to be ‘NODE’ and contains three attributes of type string.

 

clip_image002

 

* Following is a Code generated by the code wizard for reading a context node as a table operation.

 

clip_image004

 

Now let us see how the code has been generated.

 

Whenever a view has been created, an interface with name IF_<VIEW_NAME> will be created by the system and an object reference for that interface will be WD_THIS which you will be able to see in the attributes tab of the view.

 

Also whenever a view has been created a default root context node CONTEXT will be created below which we will be creating our context node and attributes. An object reference will be generated by the system WD_CONTEXT which is an instance for the root context node referring to the SAP standard interface for context nodes IF_WD_CONTEXT_NODE. This interface if_wd_context_node contains methods which is used to perform variety of operations in the context node.

 

Note : Whatever the context node we are creating under the root context node “CONTEXT” will be of type if_wd_context_node but does not have a same instance and Context nodes are like class and we need an instance to perform any action on it.

 

When ever I want to perform an action in the context node, I need to access the node first and to access that node I need an object reference. Here when I am creating a node under the root context node CONTEXT an instance for that context node will be generated by the system which I will not be aware of. Then if you look at what are the possibilites available for acquiring the object reference here it is. I have my access to my root context node “CONTEXT” which is referring to an SAP standard interface IF_WD_CONTEXT_NODE. This interface contains a method get_child_node which is used to return the object reference of its child node provided that we are passing the name of the context node for which we need the object reference.

 

Note : Using this method you can only get the object reference of the immediate child of the root node, not the child of its child node.

 

Code :

 

data : lo_node type ref to if_wd_context_node.

 

lo_node = wd_context->get_child_node( ‘NODE’ ).

 

Remember all the child of the root context node “CONTEXT” will be of type if_wd_context_node. So I am declaring a reference variable of that type to get store the object reference for my context node. Then using the object reference of the root context node ‘CONTEXT’ I am accessing the method get_child_node which gives the object reference of the child in return. Here I am exporting the name of the context node as a text and receiving the object reference of that context node in the reference variable which I created earlier.

 

 

Below is the parameters of the method get_child_node of interface if_wd_context_node.

 

clip_image006

 

Here name is the obligatory importing parameter for this method and it returns the object reference of the node using returning parameter child_node.

 

In the code wizard the name of the context node will be passed as

 

name  = wd_this->wdctx_node

 

As I mention earlier wd_this is the object reference which is created for the interface created at the time of view creation. When ever a context node has been added to the root context a constant variable will be declared in the interface with the standard naming convention for the context wdctx followed by the node name.

 

Here view name is v_main.

Interface created for that view is if_v_main.

Name of the context node created is “NODE

 

clip_image008

 

 

 

Now I have got the object reference to my context node ‘NODE’ in the reference variable ‘lo_node’. Now what ever the method of interface if_wd_context_node accessed using this object reference will be reflected in my context node.

 

To read the values in the context node there is a method get_static_attributes_table in the interface if_wd_context_node. Using this method we can get the values in the context node in the form of table.

 

Parameters of the method get_static_attributes_table are as below.

 

clip_image010

 

This methods returns the value in the form of table. To receive the value we need an internal table with the structure of the context node.

 

Code generated by the code wizard for declaring the internal table is

as below.

clip_image012

 

As we know wd_this is the object reference for the view controller. Whenever a node has been created an structure for the node with its attribute will be declared in the interface of the view.

 

clip_image014

 

 

 

Using this we can declare our internal table.

 

clip_image016

 

Using the object reference for our context node, and by accessing the get_static_attributes_table method of interface if_wd_context_node we can import the values in the context node into our internal table.

 

 

 

About Arun

3 Comments:

Powered by Blogger.