This answer from Uday Gubbala is good.
Steps to make multiple rows selectable in ALV:
1) Create the selection property of the node that you are binding to the DATA node as o..n
2) Un-check the, "Initialization Lead Selection" checkbox for the node which you are using to bind to the DATA node
3) In the WDDOINIT method specify the ALV's selection mode as MULTI_NO_LEAD
. It is important that you set the selection mode to MULTI_NO_LEAD
or else in the end you would be capturing 1 row lesser than the total number of rows the user has selected. This is because 1 of the rows would have the LeadSelection property & our logic wouldnt be reading the data for that row. Check the example code fragment as shown below:
DATA lo_value TYPE REF TO cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model( ).
CALL METHOD lo_value->if_salv_wd_table_settings~set_selection_mode
EXPORTING
value = cl_wd_table=>e_selection_mode-MULTI_NO_LEAD.
Steps to get the multiple rows selected by the user:
In order to get the multiple rows which were selected by the user you will just have to call the get_selected_elements
method of if_wd_context_node
. So as you can see its no different from how you would get the multiple rows selected by the user in a table ui element. First get the reference of the node which you have used to bind to the ALV & then call this method on it. Check the example code fragment below:
METHOD get_selected_rows .
DATA: temp TYPE string.
DATA: lr_node TYPE REF TO if_wd_context_node,
wa_temp TYPE REF TO if_wd_context_element,
ls_node1 TYPE wd_this->element_node_flighttab,
lt_node1 TYPE wd_this->elements_node_flighttab.
lr_node = wd_context->get_child_node( name = 'NODE_FLIGHTTAB' ).
" This would now contain the references of all the selected rows
lt_temp = lr_node->get_selected_elements( ).
LOOP AT lt_temp INTO wa_temp.
" Use the references to get the exact row data
CALL METHOD wa_temp->get_static_attributes
IMPORTING
static_attributes = ls_node1.
APPEND ls_node1 TO lt_node1.
CLEAR ls_node1.
ENDLOOP.
ENDMETHOD.
answered
20 Oct '11, 04:26
cschand
85●1●1
accept rate:
25%