2024 Jan 04 4:47 PM
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.
2024 Jan 05 8:03 AM
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.
2024 Jan 04 5:33 PM
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
2024 Jan 04 6:15 PM
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.
2024 Jan 04 7:49 PM
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.
2024 Jan 05 8:03 AM
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.
2024 Jan 10 1:45 PM
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.
2024 Jan 10 2:04 PM
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 ).
2024 Jan 05 8:23 AM
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.
2024 Jan 05 8:30 AM
Hopefully some people are kind enough to take time to find the answers for you and post them 😄