sapdev logo background
sapdev logo sapdev logo
Comments

SET_ATTRIBUTE method of interface IF_WD_CONTEXT_NODE to assign value to individuale context attribute




The SET_ATTRIBUTE method assignes a value to an individual field/attribute of of context element.


Single context attribute not within a node
This is the simplest form of attribute to set as you can reference it directly using the WD_CONTEXT attribute.

  wd_Context->set_attribute(
     EXPORTING
        value = '1234'   "Attribute Value
        name  = 'MY_ATTRIBUTE' ).




Single line structure context node
The abap code below assigns a value to the CARRID attribute within the context node CARRIERS.

* Set single value within context structure
Data: it_scarr type standard table of if_MAIN=>element_CARRIERS, "view name = MAIN, context = CARRIERS
      wa_scarr like line of it_scarr,
      context_node type ref to if_wd_context_node,
      lr_element TYPE REF TO if_wd_context_element.


* bind this data to the context of the flat structure
  context_node = wd_context->get_child_node( name = 'CARRIERS').
*                   CARRIERS' is the name of the context node
  lr_element = context_node->get_element( ).
  lr_element->set_attribute(
        EXPORTING
          value =  '1234'            " Attribute Value
          name  = 'CARRID' ).     " Web Dynpro: Name of Context Element


Table context node (multiple lines)
The abap code below assigns a value to the CARRID field within the context table CARRIERS. The code below loops around each row recieved and updates the field on every row.

* Set single value within context structure
Data: it_scarr type standard table of if_MAIN=>element_CARRIERS, "view name = MAIN, context = CARRIERS
      wa_scarr like line of it_scarr,
      context_node type ref to if_wd_context_node,
      lr_element TYPE REF TO if_wd_context_element.

* Retrieve new data
select *
  from scarr
  into table it_scarr
 where CARRID = 'AA' .

  context_node = wd_context->get_child_node( name = 'CARRIERS').
*                   CARRIERS' is the name of the context node

* bind this data to the context of the table
  context_node->bind_table( it_scarr ).

  if sy-subrc eq 0.
    loop at it_scarr into wa_scarr.
      free lr_element.
      free context_node.

      context_node = wd_context->get_child_node( name = 'CARRIERS').
      lr_element = context_node->get_element( sy-tabix ). "sy-tabix represents table row to reference
      lr_element->set_attribute(
        EXPORTING
          value =  '1234'      " Attribute Value
          name  = 'CARRID' ).  " Web Dynpro: Name of Context Element
    endloop.
  endif.

Also see here for how to use bind_structure to bind all values within a context node (structure) using one abap statement.
See all Methods of IF_WD_CONTEXT_NODE interface




comments powered by Disqus