The GET_ATTRIBUTE method retrieves the value of 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->get_attribute( EXPORTING name = 'MY_ATTRIBUTE' IMPORTING value = ld_attvalue "Attribute Val ).
*Declare variables used to reference context node and attributes Data: it_scarr type standard table of if_MAIN=>element_CARRIERS, "MAIN(view), CARRIERS(context) 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 * Once you have a link to the context node/structure you can then reference the individual attributes lr_element = context_node->get_element( ). lr_element->get_attribute( EXPORTING name = 'CARRID' " Web Dynpro: Name of Context Element IMPORTING value = ld_attvalue "Attribute Value ).
Table context node (multiple lines)
The abap code below retrieves the CARRID field value from within context node/table CARRIERS. Whether a context node
acts like a structure or a table can be assigned using the Cardinality setting. The code below
simply copys all row into an internal table.
* 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. 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->get_attribute( EXPORTING name = 'CARRID' IMPORTING value = ld_attvalue "Attribute Value ). endloop. endif. ***IN reality you would just use the following code to capture all rows of the table ***into an itab and then loop around the internal table(it_scarr) context_node->get_static_attributes_table( importing table = it_scarr ).
Also see here for how to use set_attribute to set individual value of a context attribute.
See all Methods of IF_WD_CONTEXT_NODE interface