Application Development 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: 

How to select multiple line blocks in ALV output

dubbaka
Participant
0 Kudos
2,127

Hello Experts,

We re displaying internal table data using CALL METHOD cl_salv_table=>factory

In output if we select two lines and hit on menu button, the lines between selected lines needs to be selected.

for example: in output lines 1,5,7 and 10 is selected and clicked on menu button, 1 to 5 lines should be selected and lines between 7 to 10 needs to be selected.

Expected results

Please let me know if anyone know any solution for this.

1 ACCEPTED SOLUTION

javier_alonso
Participant
0 Kudos
2,035

You would just need to get the selected rows and then loop between them.

DATA(selected_rows) = salv_table->get_selections( )->get_selected_rows( ).
CHECK lines( selected_rows ) EQ 2.

SORT selected_rows ASCENDING.

DATA(i) = selected_rows[ 1 ] + 1.
DATA(max) = selected_rows[ 2 ].

WHILE i < max.
  APPEND i TO selected_rows.
  i = i + 1.
ENDWHILE.

salv_table->get_selections( )->set_selected_rows( selected_rows ).

It's not the best code but you get the idea.

8 REPLIES 8

Sandra_Rossi
Active Contributor
2,035

No idea what "menu button" you're talking about, whether it's part of the Standard Application Toolbar, or a menu item, or a button in the ALV toolbar, and no idea where you're stuck, if it's about the button or if it's about the selection.

You already have many answers in the forum how to set selected lines.

set selected lines "cl_salv_table" site:sap.com

dubbaka
Participant
0 Kudos
2,035

Hi sandra.rossi,

I need to add a button in the ALV toolbar, but adding button is not a difficult job however when 1st and 5th lines are selected in output and clicked on button the lines between 1st to 5th ( 2,3,4) also should be selected, that is the requirement.

Sandra_Rossi
Active Contributor
0 Kudos
2,035

You have probably found the same good answers as I could find, so what issue do you have in implementing a loop at selected lines and to set the additional lines? I don't get what is complex, it's just one call to select additional lines.

javier_alonso
Participant
0 Kudos
2,036

You would just need to get the selected rows and then loop between them.

DATA(selected_rows) = salv_table->get_selections( )->get_selected_rows( ).
CHECK lines( selected_rows ) EQ 2.

SORT selected_rows ASCENDING.

DATA(i) = selected_rows[ 1 ] + 1.
DATA(max) = selected_rows[ 2 ].

WHILE i < max.
  APPEND i TO selected_rows.
  i = i + 1.
ENDWHILE.

salv_table->get_selections( )->set_selected_rows( selected_rows ).

It's not the best code but you get the idea.

0 Kudos
2,035

Hello javier_alonso,

Thanks for the response, However I have expecting "Select Block functionality in ALV output.

Above image is from SM30 Transaction I need to add similar functionality in ALV report output.

Kindly let me know if any one knows standard functionality to enable this option in ALV.

0 Kudos
2,035

With a SALV with selection mode as follows, you can then click on the checkbox of the first row, and then hold SHIFT and click on the last row. All between lines will be selected as well, no need of any button.

salv_table->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

thilakan_t
Participant
0 Kudos
2,035

cl_salv_table->get_selections( )->get_selected_rows( ) returns the index of selected rows(as table).

Take two index(rows) at a time and mark the intermediate lines as selected.

Finally refresh the table by calling REFRESH method.

Sandra_Rossi
Active Contributor
2,035

Hopefully some people are kind enough to take time to find the answers for you and post them 😄