How to Write Data to Context Elements in ABAP WebDynpro
How to Write Data to Context Elements in ABAP WebDynpro
In the previous lessons ,we have learnt reading attribute and structure values from context element .Now we will learn how to write data to context element in ABAP WebDynpro .Reading and Writing data to context elements is very important part for every webdynpro developer because if you know these two techniques ,you can simply build any webdynpro application .Here i am sharing two different methods that writing data to existing context elements and new context elements and how to generate new context element there after setting the values for generated element.
Writing data to Existing Context elements
Method ABAP_TUTOR9.
DATA:I_node type ref to IF_WD_CONTEXT_NODE,
I_my_struc type ref to IF_MY_CONTROLLER=>element_node_1.
I_node = wd_context->get_child_node(wd_this->wdctx_node_1).
I_node->set_static_attributes(static_attributes= I_my_struc ).
Endmethod.
Here we are using set_static_attributes method to set a single attribute value.
Writing data to Existing Context elements
As a webdynpro developer,many times ,we require additional node element to store additional data so that this element must be generated before the attributes can be given values.To achieve this functionality ,we have to put some extra effort.
a. Create the new Element.
b. Set the corresponding values of the attributes.
c. Binding the new element into the node hierarchy.
Method ABAP_TUTOR6.
DATA:I_node type ref to IF_WD_CONTEXT_NODE,
I_new_element type ref to IF_WD_CONTEXT_ELEMENT,
I_my_struc type ref to IF_MY_CONTROLLER=>element_node_1.
I_node = wd_context->get_child_node(wd_this->wdctx_node_1).
I_new_element->set_static_attributes(static_attributes= I_my_struc ).
I_node->bind_element(I_new_element)
Endmethod.
And also, we can define the position of the new element in the run-time context.using the Bind_Element method importing index parameter.
Now let us learn the importance of two methods
Bind_Structure and Bind_Table methods
We are using the Bind_structure method to generate the new context elements into one step and sets the values of the attributes with the values of the I_my_struc local variable and binds the new element into run-time context.
Method ABAP_TUTOR7.
DATA:I_node type ref to IF_WD_CONTEXT_NODE,
I_my_struc type ref to IF_MY_CONTROLLER=>element_node_1.
I_node = wd_context->get_child_node(wd_this->wdctx_node_1).
I_node->Bind_Structure (new_Item = I_my_struc )
Endmethod.
We are using Bind_Table method to merge the set of context elements corresponding to internal table at a time .
Method ABAP_TUTOR8.
DATA:I_node type ref to IF_WD_CONTEXT_NODE,
I_my_table type ref to IF_MY_CONTROLLER=>element_node_1.
I_node = wd_context->get_child_node(wd_this->wdctx_node_1).
I_node->Bind_Table (new_Item = I_my_table )
Endmethod.
Here ,we notice one thing that all binding methods have the Set_Initial_Elements parameter.
if its value is preset to true.when the bind method is called ,all existing elements of context node are deleted. if its value is preset to false. then no elements are deleted and generated elements added to corresponding positions.
I_node->Bind_Table (Set_Initial_Elements =false new items = I_my_table )
From this lesson ,we have learnt the writing data to existing and new context elements and binding data structure and table to context node .
Comments
Post a Comment