Get selected row of ABAP web dynpro table

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 inorder to perform further processing. These two methods assume lead selection is being used, if lead selection is not active on your table element then you will need to use the GET_SELECTED_ELEMENTS method to retrieve the selected rows.

There is actually a number of ways to do this, one is by creating an 'onSelect' event method for your table. A second method is a more generic way which allows you to add the functionality to any action/process within your wdp application. You could therefor have a separate button which captures which row has been selected.

First step to implementing this is to create a basic web dynpro application which conatians a table and a button

Generic Method - Add code to your button action method
From the actions tab you can double click on your button ACTION to view its associated method and add the below ABAP code to it. '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_view1=>element_CARRIERS,
        wa_scarr like line of it_scarr.
  data: ld_element   type ref to if_wd_context_element.
  context_node = wd_context->get_child_node( name = 'CARRIERS').
  ld_element   = context_node->get_lead_selection( ).
  if  not ld_element is INITIAL.
    ld_element->get_static_attributes( IMPORTING
                                        static_attributes = wa_scarr ).
  endif.
* Data of selected row is now contained in wa_scarr


onSelect Event Method - Add code to your table onSelect Event
From the table UI element within the layout tab create an 'onSelect' event, ensuring that you 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_view1=>element_CARRIERS,
        wa_scarr like line of it_scarr.
  DATA: ld_index type i.
*NEW_LEAD_SELECTION should be an importing parameter of the method which was auto created
*There should also be an OLD_LEAD_SELECTION showing the previous selected row!
  ld_index = NEW_LEAD_SELECTION->GET_INDEX( ). "get index of row selected
  context_node = wd_context->get_child_node( name = 'CARRIERS').
  refresh: it_scarr.
* Get data contained within ABAP web dynpro table
  context_node->get_static_attributes_table(
    importing
      table = it_scarr ).
* Get data contained in currently selected row of an ABAP web dynpro table
  context_node->GET_STATIC_ATTRIBUTES(
     exporting index = ld_index
     importing STATIC_ATTRIBUTES = wa_scarr ).

Set all Methods of IF_WD_CONTEXT_NODE interface


Related Articles

Add programmed/OVS search help to FPM ESS/MSS application via enhancement to CL_HRESS_PER_DETAIL
BIND_STRUCTURE method of interface IF_WD_CONTEXT_NODE to assign structure to context
BIND_TABLE method of interface IF_WD_CONTEXT_NODE
Get the name of the button the user has clicked on within the SAP web dynpro action ABAP code
Create field Refering to datatype of webDynpro context element
WebDynpro context for creation of screen field including standard search help
Disable SAP User Personalisation in Web Dynpro app using WDDISABLEUSERPERSONALIZATION and WDENABLEUIELEMENTSHIDE
GET_ATTRIBUTE method of interface IF_WD_CONTEXT_NODE to retrieve value of context element
GET_SELECTED_ELEMENTS to get selected row of ABAP web dynpro table when not using lead selection
GET_STATIC_ATTRIBUTE_TABLE method to return all rows of a context table node
IF_WD_CONTEXT_NODE interface methods withn ABAP Web Dynpro to enable users to view and change data
ABAP code to manually trigger ABAP web dynpro plug
Popuate SAP WebDynpro field
Freely Programmed search help for your web dynpro application (custom value help/OVS)
Change the stylesheet theme used by your web dynpro and portal apps (i.e. SAP_TRADESHOW, SAP_CORBU)
Change the stylesheet theme used by your web dynpro and portal apps (i.e. SAP_TRADESHOW, SAP_CORBU)
SET_ATTRIBUTE method of interface IF_WD_CONTEXT_NODE to assign value to individuale context attribute
Clear context attribute using SET_ATTRIBUTE_NULL method of interface IF_WD_CONTEXT_NODE
Add Dropdown by index UI Element to table field within abap web dynpro
Add freely Programmed search help to a web dynpro application field
Retrieve SAP webDynpro field value entered by user
ABAP Web dynpro ALV report table
Hide fields of a web dynpro ALV table
Display web dynpro ALV report select options to resict output results
Assign value to ABAP web dynpro context via table, structure or individual attribute
Get selected ABAP Web dynpro dropdown byindex value (dropdownbyindex UI element)
ABAP web dynpro Dropdown by index UI Element allows a field to display a drop down list of values
ABAP web dynpro Dropdown default value, allow you to set current value of dropdown UI element
Change SAP web dynpro logon screen
Read ABAP Web dynpro table context on action / button click
ABAP Web Dynpro tables to allow users to view and change data
Get all selected rows of table within your web dynpro for ABAP applications using GET_SELECTED_ELEMENTS
Get selected row of ABAP web dynpro table
ABAP Web Dynpro tree structure, display HR org structure as example
SAP ABAP Web Dynpro UI elements
View Container UI Element to display a web dynpro view within a wdp view
ALV ABAP Web Dynpro application
ABAP Web dynpro button click / Action
Call URL from SAP Webdynpro for ABAP ACTION
Call URL from SAP Webdynpro for ABAP ACTION
Display popup screen within ABAP Web dynpro
ABAP Web dynpro populate table on action / button click
ABAP code to Print abap web dynpro table
Adding URL parameters to you ABAP webdynpro to change thinks like the CSS