Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get selected rows using ALV - CL_SALV classes

bruno_franzini1
Explorer
56,957

Hi,

Please, need some help.

In my ALV report - Using CL_SALV classes, how can I process multiple lines?

For example: I've set to display "select all button".

Need select a few lines, in this case, has been selected 2 rows and executed a call transaction using two rows. But there's something else to do, 'cause all rows in ALV report executed the Call Transaction.

Just found the following:

layout-box_fname = "field name".

layout-sel_mode   = 'A'.

But to use in CL_GUI_ALV_GRID, I DO NOT want to change it right now, 'cause the ALV report is almost done.

What's the corresponding for 'BOX_FNAME' and 'SEL_MODE' of CL_GUI_ALV_GRID inside CL_SALV classes?


Thanks and Regards.

1 ACCEPTED SOLUTION
Read only

custodio_deoliveira
Active Contributor
23,569

Hi Bruno,

In the method where you handle the event you need to use cl_salv_selections to see which rows are selected. then you perform the action only for these rows, by reading your internal table with the indexes in the selection.  something like this :

data: lo_selections type ref to cl_salv_selections.

data lt_rows   type salv_t_row.

data ls_row type 1.

   lo_selections = lo_alv->get_selections( ).

   lt_rows = lo_selections->get_selected_rows( ).

loop at lt_rows into ls_row.

read table lt_alv_table_data index ls_row.

* do the action

endloop.

You can also have a look at program SALV_TEST_TABLE_SELECTIONS

Regards,

Custodio

6 REPLIES 6
Read only

custodio_deoliveira
Active Contributor
23,570

Hi Bruno,

In the method where you handle the event you need to use cl_salv_selections to see which rows are selected. then you perform the action only for these rows, by reading your internal table with the indexes in the selection.  something like this :

data: lo_selections type ref to cl_salv_selections.

data lt_rows   type salv_t_row.

data ls_row type 1.

   lo_selections = lo_alv->get_selections( ).

   lt_rows = lo_selections->get_selected_rows( ).

loop at lt_rows into ls_row.

read table lt_alv_table_data index ls_row.

* do the action

endloop.

You can also have a look at program SALV_TEST_TABLE_SELECTIONS

Regards,

Custodio

Read only

0 Likes
23,569

Hi,

Custodio, thanks for reply.

Worked fine, exactly what I needed.

DATA: lt_rows TYPE salv_t_row,

         ls_rows TYPE i.

   lt_rows = o_selections->get_selected_rows( ).

   LOOP AT lt_rows INTO ls_rows.

     READ TABLE it_outtab ASSIGNING <fs_outtab> INDEX ls_rows.


Thanks a lot.

Read only

Sandra_Rossi
Active Contributor
23,569

For future visitors, concerning the other part of the question: "What's the corresponding for 'BOX_FNAME' of CL_GUI_ALV_GRID inside CL_SALV classes?

(which corresponds to adding a selection column at the left of rows, it's like a selection button in front of each row)

Answer: this feature is not enabled with SALV; but the rows can be still selected by clicking any of their cells

NB: the default selection mode is NONE (which in fact acts like SINGLE - select one row only (!?)) and can be changed to other modes like multiple rows by calling:

lo_selections->SET_SELECTION_MODE( IF_SALV_C_SELECTION_MODE=>MULTIPLE ).
Read only

0 Likes
23,569

This was helpful , Thanks 🙂

Read only

0 Likes
23,569

zebashah22 Thanks. Please use the vote button in the side bar to "like" or "dislike" 😉

Read only

23,569

Thank you so much Sandra Rossi, it was very much helpful.