Show TOC Start of Content Area

Background documentation Writing Data to New Context Elements  Locate the document in its SAP Library structure

In many cases, an additional node element is needed to store further data. This element must be generated before the attributes can be given values.

The graphic below shows an example schema that requires a fourth context element and a corresponding data record.

 

This graphic is explained in the accompanying text

 

In principle, three steps are required to do this:

       1.      Creating the new element

       2.      Setting the values of the corresponding attributes

       3.      Binding the new element into the node hierarchy

 

 

method EXAMPLE .  

 

data: l_node                     type ref to IF_WD_CONTEXT_NODE,

      l_new_element              type ref to IF_WD_CONTEXT_ELEMENT,

      l_my_struc                 type ref to IF_MY_CONTROLLER=>element_node_1.

 

. . . . . . . . . 

l_node = wd_context->get_child_node( wd_this->wdctx_node_1 ).

 

l_new_element     = l_node->create_element( ).

l_new_element->set_static_attributes( static_attributes = l_my_struc ).

l_node->bind_element( l_new_element ).

. . . . . . . . .

 

endmethod.

   

 

The BIND_ELEMENT method has an INDEX importing parameter. This means that there is an opportunity here to define the position of the new element in the runtime context. If no value is passed in this position, the new element is automatically sorted into a position following the last element prior to the addition.

BIND_STRUCTURE and BIND_TABLE Methods

The BIND_STRUCTURE method can be used to merge this way of generating a new context element into one step.

 

method EXAMPLE .  

 

data: l_node                     type ref to IF_WD_CONTEXT_NODE,

      l_my_struc                 type ref to IF_MY_CONTROLLER=>element_node_1.

 

. . . . . . . . .

l_node = wd_context->get_child_node( wd_this->wdctx_node_1 ).

 

l_node->bind_structre( new_item = l_my_struc ).

. . . . . . . . .

 

endmethod.

   

The BIND_STRUCTURE method generates a new context element, sets the values of the attributes with the values of the l_my_struc local variable, and binds the new element into the runtime context.

If several new elements are to be bound into a runtime context at the same time, and you would therefore need to call the BIND_STRUCTURE method several times in a row, you can bind a set of elements with a single call instead. A set of context elements corresponds to an internal table in ABAP Objects. The method for binding in several new context elements at the same time is therefore called BIND_TABLE.

 

method EXAMPLE .  

 

data: l_node                     type ref to IF_WD_CONTEXT_NODE,

      l_my_table                 type ref to IF_MY_CONTROLLER=>elements_node_1.

 

. . . . . . . . .

l_node = wd_context->get_child_node( wd_this->wdctx_node_1 ).

 

l_node->bind_table( new_items = l_my_table ).

. . . . . . . . .

 

endmethod.

   

 

Caution In this case, the local variable has the type IF_MY_CONTROLLER=>elements_node_1 and the formal parameter is called NEW_ITEMS.

 

All BIND methods have the SET_INITIAL_ELEMENTS parameter. Its value is preset to true. As a result, all elements of the context node that are available when the BIND method is called are deleted. After the call, the context only has those elements that were generated and inserted by the BIND method. However, if the context elements to be generated are to be added to the existing elements, the SET_INITIAL_ELEMENTS must be passed with the value false.

 

. . . . . . . . .

 

l_node->bind_table( set_initial_elements = false new_items = l_my_table ).

. . . . . . . . .

 

In this case, the elements are placed in one of the following positions:

      At the beginning (if the index value is not passed)

      At the position defined by the index value

.

 

Note The use of the two BIND methods results in an optimization of element generation at runtime in comparison with multiple use in accordance with the detailed programming example at the beginning of this section.

 

 

 

 

 

End of Content Area