sapdev logo background
sapdev logo sapdev logo
Comments

GET_SELECTED_ELEMENTS to get selected row of ABAP web dynpro table when not using lead selection




Once you have added a table to your web dynpro for ABAP application you may need to find out which row has been selected by the user. If you are using lead selection on the table you also need to check out GET_LEAD_SELECTION for information on how to processes this, alternatively the below abap code shows how to get which row was selected when lead selection is not being used. .

First step to implementing this is to create a basic web dynpro application which conatians a table ensuring you dont tick the 'intialization Lead Selection' within the context and set the selectionMode within the table element to 'MultiNoLead' or 'SingleNoLead'.

onSelect Event Method - Not using lead selection on table
From the table UI element within the layout tab create an 'onSelect' event, you do not need to tick the 'Transfer UI Event Parameters' checkbox. Now add the following code to the resultant event method. Again 'CARRIERS' is the context node assigned to the table.

  Data: context_node type ref to if_wd_context_node.
  Data: it_scarr type STANDARD TABLE OF if_MAIN=>element_CARRIERS,
        wa_scarr like line of it_scarr,
        wa_selrow like line of it_scarr,
        ld_element   type ref to if_wd_context_element,
        it_rows  type WDR_CONTEXT_ELEMENT_SET,
        wa_rows like line of it_rows.
  DATA: ld_index type i.

  context_node = wd_context->get_child_node( name = 'CARRIERS' ).
  context_node->get_static_attributes_table(
    importing
      table = it_scarr ).

  ld_element   = context_node->get_lead_selection( ).
  it_rows  = context_node->GET_SELECTED_ELEMENTS( ).

  LOOP AT it_rows INTO wa_rows.
    CALL METHOD wa_rows->get_static_attributes
        IMPORTING
          static_attributes = wa_selrow.

  read TABLE it_scarr into wa_scarr with key carrid = wa_selrow-carrid.
  ld_index = sy-tabix. "index of selected row
* You can now do what you want with this, store in in a global variable so that you
* can build up a list of rows selected by user allowing them to select multiple rows.
* If you do this you simply need to use context_node->set_selected to select all the
* rows you have captured each time, remember to deselect any rows clicked on twice

*   SELECT a row
*   context_node->set_selected(
*       flag = abap_true
*       index = ld_index ).

*   DE-SELECT a row
*   context_node->set_selected(
*       flag = abap_false
*       index = ld_index ). 
  ENDLOOP.

Set all Methods of IF_WD_CONTEXT_NODE interface




comments powered by Disqus