Skip to end of metadata
Go to start of metadata

Frequently Asked Questions - Context Issues

This section of the FAQ provides answers to questions about the Web Dynpro context.


What Can I Do If I Have Context Problems?

How do I read user input (e.g. inputfields) from context?

How do I get all selected elements of a context node?

How can I select elements of a node program controlled?

How can I dynamically create a context node during runtime?


What Can I Do If I Have Context Problems?

Go ahead as described in SAP note 999992.
back to top

How do I read user input (e.g. inputfields) from context?

You created a view with several input fields and you want to get the entered values for processing
(e.g. save to database).

Add a button UIElement to your view. In the properties tab of the button add a handler for the
onAction event. Go to the action handler method you just created. Now you can use the wizard to
automatically create the method calls to read the data from context.

As example consider the following context structure:

  • node_for_inputfields (cardinality 1:1)
    • attribute_name (type String)
    • attribute_text (type String)

Both attributes are bound to the inputfields of the view.

After using the wizard in the action handler method the necessary code will look as follows:

data:
         Node_Node_For_inputfields type ref to If_Wd_Context_Node,
         Elem_Node_For_inputfields type ref to If_Wd_Context_Node,
         Stru_Node_For_inputfields Wd_This->Element_Txe_Barcodes. 

Node_Node_For_inputfields = wd_context->get_child_node( name = if_v_viewname=>wdctx_Node_For_inputfields ).
Elem_Node_For_inputfields = Node_Node_For_inputfields->get_element(  ).
Elem_Node_For_inputfields->get_static_attributes(
    IMPORTING
      static_attributes = Stru_Node_For_inputfields ). 

* Place code for processing entered values here

Stru_Node_For_inputfields is the structure of the context node and can be handled as normal structure to process the entered values.
back to top

How do I get all selected elements of a context node?

data:
        lr_context_node        type ref to if_wd_context_node,
        lr_context_element     type ref to if_wd_context_element.

  data:
        lt_selected_elements   type wdr_context_element_set.

  data:
        ls_some_structure      type some_structure.

  lr_context_node = wd_context->get_child_node( name = 'NAME' ).
  lt_selected_elements = lr_context_node->get_selected_elements( ).

  loop at lt_selected_elements into lr_context_element.
    lr_context_element->get_static_attributes(
      static_attributes = ls_some_structure
    ).

*    do something with the element or its attributes.
  endloop

This code could be used to get all selected elements of a table UIElement and do some processing.
back to top

How can I select elements of a node program controlled?

You can use the following code to select an element of a context node. In this example the
5th element of a context node is selected.

data:
      lr_context_node    type ref to if_wd_context_node.

data:
      lv_index           type i.

lv_index = 5.

lr_context_node = wd_context->get_child_node( name = 'NAME' ).
lr_context_node->set_selected(
   flag = abap_true
   index = lv_index
).

To select all elements of a context node the following extension of the above example can be used.

data:
      lr_context_node    type ref to if_wd_context_node.

data:
      lv_element_count   type i.

lr_context_node = wd_context->get_child_node( name = 'NAME' ).
lv_element_count = lr_context_element->get_element_count( ).

do lv_element_count times.
lr_context_node->set_selected(
   flag = abap_true
   index = sy-index
).
enddo.

To deselect certain elements the parameter 'flag' of the set_selected method has to be set to abap_false.
back to top

How can I dynamically create a context node during runtime?

You can dynamically create nodes in the context using the utility class cl_wd_dynamic_tool.
The following example code creates a new node with the structure SFLIGHT and bind all
entries of the SFLIGTH table to this new node.

data:
      lr_rootnodeinfo       type if_wd_context_node_info,
      lr_new_node           type if_wd_context_node.

data:
      lt_filgths            type table of sflight.

lr_rootnodeinfo = wd_context->get_node_info( ).

cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
      parent_info = lr_rootnodeinfo
      node_name = 'FLIGHTS'
      structure_name = 'SFLIGHT'
      is_multiple = abap_true ).

lr_new_node = wd_context->get_child_node( 'FLIGHTS ).

select * from sflight
 into corresponding fields of table lt_flights.

lr_new_node->bind_table( lr_flights ).

back to top

1 Comment

  1. Unknown User (1076piw7g)

    A very good and helpful material. I could clear all my doubts regarding context nodes.