cancel
Showing results for 
Search instead for 
Did you mean: 

How to access attribute

Former Member
0 Kudos

Hi all,

I am new to webdynpro for ABAP. How to access the attribute which is directly under the root context.

ex.

Root Context

|

Name ---> attribute.

Regards,

Gnid.

Accepted Solutions (0)

Answers (2)

Answers (2)

S-H
Active Participant
0 Kudos

Hi Gopi,

Accessing a context element or a context attribute requires to first have a reference to the related context node. The context root node can be accessed by the standard attribute WD_CONTEXT.

To Access a Node Element: After having accessed a context node, the reference to the element at lead selection of this node can be obtained by calling the method get_element( ). Thismethod returns a reference to the element instance of type IF_WD_CONTEXT_ELEMENT. Accessing the Node Element at Lead Selection The element with index n can be accessed using the method get_element( index = n ) .

Once we access the element we can access the attribute by GET_ATTRIBUTE().

Child nodes of the context root node can be identified using the get_child_node( ) method. This method returns a reference to the node instance of type IF_WD_CONTEXT_NODE. The get_child_node( ) method requires the name of the node and, optionally, the index of the element in the parent node to which the desired node instance belongs. In this case, the parent node is the context root, which only ever has one element; therefore, the index parameter is 1 (default = lead selection of parent element).

Best regards,

Suresh

Message was edited by:

Suresh Honnappanavar

S-H
Active Participant
0 Kudos

Hi Gopi,

If you have declared a attribute 'TEXT' directly below the root contrex then to access this attribute the following code may help.

Sample code:

DATA lo_el_context TYPE REF TO if_wd_context_element.

DATA ls_context TYPE wd_this->element_context.

DATA lv_text LIKE ls_context-text.

lo_el_context = wd_context->get_element( ).

lo_el_context->get_attribute(

EXPORTING

name = `TEXT`

IMPORTING

value = lv_text ).

The variable LV_TEXT will have the value of the context attribute.

The best/simple approach is to use the WebDynpro Code Wizard (keyboard short cut CNTRL + F7 ) in the method.

Best regards,

Suresh

Message was edited by:

Suresh Honnappanavar

Former Member
0 Kudos

hi ,

Thanks for the quick reply.

I have one more issue. I have bound this attribute to an input field. when i click i want to display this value in the next view. for this i have created this attribute in the controller also.

But the problem is that i am unable to map this controller context attribute to view context attribute.

Why is it so? and how to acheive that.

Regards,

Gnid.

S-H
Active Participant
0 Kudos

Hi Giri,

If you have created attribute directly below the root node in component controller context then it cannot be mapped in the view controllers context. The reason is that we can only map the node between the controller's.

Please create a node in Component controller, create the attribute under this node and then we can map it to all the views.

If you have created the Node in the Component controller but still in the View's context tab you are not able to see the Component controller context. Then check if the Component controller usage has been declared in the Views Property tab.

Best regards,

Suresh

Message was edited by:

Suresh Honnappanavar

Message was edited by:

Suresh Honnappanavar