cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting all rows of an ALV without using ALV controls.

Former Member
0 Kudos

I need to select all the rows in a Web Dynpro ALV using an external control (I mean, pushing a button that does not belong to the ALV).

How can I get control over row selection? I see nothing about that in the model, or maybe I'm missing something...

Thanks in advance,

S.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First,you need to set selection attribute of context node as 0...n.

Second,you need to add code in your action method. When you click one button, this method will be

called. Below is sample of code. Hope that these are helpful.

--


All rows will be selected by this code--

DATA: EXPORTING_NODE TYPE REF TO IF_WD_CONTEXT_NODE,

LT_ELEMENTS TYPE WDR_CONTEXT_ELEMENT_SET,

LS_ELEMENTS TYPE REF TO IF_WD_CONTEXT_ELEMENT,

LR_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE,

LR_CONFIG_TABLE TYPE REF TO CL_SALV_WD_CONFIG_TABLE,

LR_SALV_SETTINGS TYPE REF TO IF_SALV_WD_TABLE_SETTINGS.

EXPORTING_NODE = WD_CONTEXT->GET_CHILD_NODE( 'EXPORTING' ).

CALL METHOD EXPORTING_NODE->GET_ELEMENTS

RECEIVING

SET = LT_ELEMENTS.

LOOP AT LT_ELEMENTS INTO LS_ELEMENTS.

LS_ELEMENTS->SET_SELECTED( ABAP_TRUE ).

ENDLOOP.

LR_INTERFACECONTROLLER = WD_THIS->WD_CPIFC_ALV_GRID( ).

LR_CONFIG_TABLE = LR_INTERFACECONTROLLER->GET_MODEL( ).

LR_SALV_SETTINGS ?= LR_CONFIG_TABLE.

CALL METHOD LR_SALV_SETTINGS->SET_SELECTION_MODE

EXPORTING

VALUE = CL_WD_TABLE=>E_SELECTION_MODE-MULTI_NO_LEAD.

--


All rows will be selected by this code--

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Now coming to the 2nd part i.e, to select all the rows in the ALV:

1) Get the count of rows in the ALV

2) Use the set_selected method up on all these rows to mark them as selected.

Check the coding below: (You need to place this coding within the action handler of your custom button.)

METHOD onactiondeselect_all_rows .
  DATA: wd_node TYPE REF TO if_wd_context_node,
        lines_count TYPE i VALUE 0.
 
  wd_node = wd_context->get_child_node( name = 'NODE1' ).
  CALL METHOD wd_node->get_element_count
    RECEIVING
      count = lines_count.
  DO lines_count TIMES.
    wd_node->set_selected( flag  = ''
                           index = sy-index ).
  ENDDO.
ENDMETHOD.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Soledad,

Working with ALV is similar to working with a normal Table ui element. So in order to select all the rows in an ALV by pressing a custom button you need to use the SET_SELECTED method of if_wd_context_node method. But before this you need to set the selection mode of the ALV to MULTI_NO_LEAD.

In order to select the MULTI_NO_LEAD selection mode for the ALV you can proceed as follows:

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.

Former Member
0 Kudos

Hi,

In the cutom button handler,

In the context node- if_wd_context_node you can use the get_elements and

also the selection mode of the alv should be Mutli or MultiNolead

Loop at the lt_elements into lr_element
lr_element->set_selected( abap_true ).
endloop.
    CALL METHOD lr_model->if_salv_wd_table_settings~set_selection_mode
      EXPORTING
        value = cl_wd_table=>e_selection_mode-multi_no_lead.

Or In the latest version, you can see left hand top corner an expand icon on ALV for select all and deselect all. Please try to use it if required.

Regards,

Lekha.