‎2007 Feb 08 12:22 PM
HI TO ALL,
HOW TO TRANSFER THE SELECTED ROWS FROM THE ALV GRID CONTAINER TO THE INTERNAL TABLE,
PLZ SEND SOME EXAMPLES TOO,
THANKS IN ADVANCE
‎2007 Feb 08 12:30 PM
Hi Ramesh,
<b>data : gi_index_rows TYPE lvc_t_row,
g_selected_row LIKE lvc_s_row.
REFRESH gi_index_rows.
CLEAR g_selected_row.
CALL METHOD obj_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
LOOP AT gi_index_rows INTO g_selected_row.
READ TABLE itab INDEX g_selected_row-index INTO
wa_itab.
..............
.............. " move all the fields wa_itab to jtab.
..............
ENDLOOP.
</b>
‎2007 Feb 08 12:56 PM
Refer this code sample
INCLUDE <icon>.
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
CLASS lcl_event_receiver DEFINITION DEFERRED.
CLASS cl_gui_container DEFINITION LOAD.
DATA : o_alvgrid TYPE REF TO cl_gui_alv_grid,
o_dockingcontainer TYPE REF TO cl_gui_docking_container,
o_eventreceiver TYPE REF TO lcl_event_receiver.
CLASS lcl_event_receiver DEFINITION.
* event receiver definitions for ALV actions
PUBLIC SECTION.
CLASS-METHODS:
* Status bar
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_user_command.
* In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
CASE e_ucomm.
WHEN 'FCODE'.
CALL METHOD o_alvgrid->get_selected_rows
IMPORTING
et_index_rows = i_selected_rows
* ET_ROW_NO =
.
IF i_selected_rows[] IS INITIAL.
MESSAGE i153 WITH text-009.
LEAVE LIST-PROCESSING.
ENDIF.
CLEAR: w_reviewed_mat.
* w_reviewed_mat-reviewed = c_x.
* w_reviewed_mat-reviewedby = sy-uname.
* w_reviewed_mat-reviewedon = sy-datum.
LOOP AT i_selected_rows INTO w_selected_rows.
READ TABLE i_output INTO w_output INDEX w_selected_rows-index.
IF sy-subrc EQ 0.
w_reviewed_mat-matnr = w_output-matnr.
ENDIF.
APPEND w_reviewed_mat TO i_reviewed_mat.
CLEAR: w_reviewed_mat-matnr.
ENDLOOP.
* MODIFY zzcs_mat FROM TABLE i_reviewed_mat.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
In PBO after creating container
SET HANDLER o_eventreceiver->handle_user_command FOR o_Alvgrid.
‎2007 Feb 09 3:59 AM
Hello Ramesh
As Judith already showed you can retrieve the selected grid rows using method GET_SELECTED_ROWS. However, I would like to add a few remarks to her coding:
- If you need icons in your program do no longer use INCLUDE <icon>. but instead use
TYPE-POOLS: icon. " valid since release 6.20If you simply want to get the selected grid rows at PAI of your dynpro then you do not need any event handling. Simply code:
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
...
CALL METHOD o_alvgrid->get_selected_rows
IMPORTING
et_index_rows = gt_selected_rows
* ET_ROW_NO =
.
...
ENDMODULE. " USER_COMMAND_0100 INPUT- If you need to get the selected rows within an event handling method perhaps it is better to use the SENDER instance instead of the (globally) defined grid instance, e.g.:
* event receiver definitions for ALV actions
PUBLIC SECTION.
CLASS-METHODS:
* user commands from grid toolbar
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender. " = grid instance that raised the event
...
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_user_command.
* In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
...
CALL METHOD sender->get_selected_rows
IMPORTING
et_index_rows = gt_selected_rows
* ET_ROW_NO =
.
...Regards
Uwe