09-02-2008 9:18 PM
Hello,
I'm trying to use the ALV Object model. I've added the option for the user to select multiple rows (via set_selection_mode ROW_COLUMN). However, after the user has selected rows and pushes the continue button, I don't find any data with the method get_selected_rows. What could be causing this problem? I noticed that in the method get_selected_rows he doesn't get passed this statement:
if rows_rec = abap_false.
===> row_rec is 'X'....
Thanks for your advice!
09-03-2008 5:39 PM
Hi,
Try this..
If you are displaying the SALV in a container...Then call the method get_metadata...before calling the get_selected_rows..method..
Sample code..
DATA: g_container TYPE scrfname VALUE 'CONTAINER1'.
DATA: g_custom_container TYPE REF TO cl_gui_custom_container.
TYPES: BEGIN OF type_output,
matnr TYPE matnr,
END OF type_output.
DATA:lt_output TYPE STANDARD TABLE OF type_output,
lwa_rows TYPE int4,
lwa_output TYPE type_output,
lt_rows TYPE salv_t_row.
* Local declarations.
DATA: lr_table TYPE REF TO cl_salv_table,
lr_selections TYPE REF TO cl_salv_selections.
DATA: lr_columns TYPE REF TO cl_salv_columns_table.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
START-OF-SELECTION.
* Prepare data.
lwa_output-matnr = 'TEST1'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST2'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST3'.APPEND lwa_output TO lt_output.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
SET PF-STATUS 'TEST'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
* Call the factory method
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = g_custom_container
container_name = 'CONTAINER1'
IMPORTING
r_salv_table = lr_table
CHANGING
t_table = lt_output ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
* Column selection
lr_selections = lr_table->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
lr_columns = lr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
* Display
lr_table->display( ).
ENDIF.
ENDMODULE. "pbo OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
MODULE pai INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN 'GET_ROWS'.
LEAVE TO LIST-PROCESSING.
CALL METHOD lr_table->get_metadata. " call this method....
* Get the selected rows.
lt_rows = lr_selections->get_selected_rows( ).
* Display the selected rows.
LOOP AT lt_rows INTO lwa_rows.
READ TABLE lt_output INTO lwa_output INDEX lwa_rows.
WRITE: / lwa_output-matnr.
ENDLOOP.
ENDCASE.
ENDMODULE. "pai INPUT
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM exit_program.
LEAVE PROGRAM.
ENDFORM. "exit_program
Thanks
Naren
09-02-2008 9:27 PM
It is working fine for me.
Check report: BCALV_EDIT_05
Regards,
Naimesh Patel
09-22-2013 10:13 PM
09-02-2008 9:49 PM
Hi,
Check this sample code of popup using ALV OM model with a checkbox to select rows.
TYPES: BEGIN OF type_output,
matnr TYPE matnr,
END OF type_output.
DATA:lt_output TYPE STANDARD TABLE OF type_output,
lwa_rows TYPE int4,
lwa_output TYPE type_output,
lt_rows TYPE salv_t_row.
* Local declarations.
DATA: lr_table TYPE REF TO cl_salv_table,
lr_selections TYPE REF TO cl_salv_selections.
DATA: lr_columns TYPE REF TO cl_salv_columns_table.
START-OF-SELECTION.
* Prepare data.
lwa_output-matnr = 'TEST1'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST2'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST3'.APPEND lwa_output TO lt_output.
* Call the factory method
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = 'X'
IMPORTING
r_salv_table = lr_table
CHANGING
t_table = lt_output ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
* Popup
lr_table->set_screen_popup(
start_column = 5
end_column = 90
start_line = 5
end_line = 15 ).
* Column selection
lr_selections = lr_table->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
lr_columns = lr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
* Display
lr_table->display( ).
* Get the selected rows.
lt_rows = lr_selections->get_selected_rows( ).
* Display the selected rows.
LOOP AT lt_rows INTO lwa_rows.
READ TABLE lt_output INTO lwa_output INDEX lwa_rows.
WRITE: / lwa_output-matnr.
ENDLOOP.
Thanks
Naren
09-03-2008 7:00 AM
Hello,
Thank you for the replies. I tried to use the code provided (and it works), but when I put my ALV in a container on my screen '0100' it doesn't work anymore. Do you need to provide extra parameters in order to be able to use selection from an ALV in a screen?
Thank you!
09-03-2008 9:47 AM
The list on the screen '0100' has the extra column to make multiple row selections, however in my process after input module the table remains empty when the user has selected 1 or more lines:
gr_rows = gr_selections->get_selected_rows( ).
09-03-2008 5:39 PM
Hi,
Try this..
If you are displaying the SALV in a container...Then call the method get_metadata...before calling the get_selected_rows..method..
Sample code..
DATA: g_container TYPE scrfname VALUE 'CONTAINER1'.
DATA: g_custom_container TYPE REF TO cl_gui_custom_container.
TYPES: BEGIN OF type_output,
matnr TYPE matnr,
END OF type_output.
DATA:lt_output TYPE STANDARD TABLE OF type_output,
lwa_rows TYPE int4,
lwa_output TYPE type_output,
lt_rows TYPE salv_t_row.
* Local declarations.
DATA: lr_table TYPE REF TO cl_salv_table,
lr_selections TYPE REF TO cl_salv_selections.
DATA: lr_columns TYPE REF TO cl_salv_columns_table.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
START-OF-SELECTION.
* Prepare data.
lwa_output-matnr = 'TEST1'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST2'.APPEND lwa_output TO lt_output.
lwa_output-matnr = 'TEST3'.APPEND lwa_output TO lt_output.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
SET PF-STATUS 'TEST'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
* Call the factory method
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = g_custom_container
container_name = 'CONTAINER1'
IMPORTING
r_salv_table = lr_table
CHANGING
t_table = lt_output ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
* Column selection
lr_selections = lr_table->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
lr_columns = lr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
* Display
lr_table->display( ).
ENDIF.
ENDMODULE. "pbo OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
MODULE pai INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'BACK'.
PERFORM exit_program.
WHEN 'GET_ROWS'.
LEAVE TO LIST-PROCESSING.
CALL METHOD lr_table->get_metadata. " call this method....
* Get the selected rows.
lt_rows = lr_selections->get_selected_rows( ).
* Display the selected rows.
LOOP AT lt_rows INTO lwa_rows.
READ TABLE lt_output INTO lwa_output INDEX lwa_rows.
WRITE: / lwa_output-matnr.
ENDLOOP.
ENDCASE.
ENDMODULE. "pai INPUT
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM exit_program.
LEAVE PROGRAM.
ENDFORM. "exit_program
Thanks
Naren
03-14-2011 10:13 AM
Hey,
i just wanted to say, that i had similar problem and the solution from Narendran Muthukumaran worked perfect.
Greets,
Kuba
03-22-2016 3:56 AM