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

problem with gt_grid

Former Member
0 Likes
573

Hello,

I am debugging through sap system code and i reached the following:

in form Marks_save there is an abap statement

call method gt_grid-grid->get_selected_rows

but they did not define gt_grid anywhere.

In the abap function that I am writing, I wrote the following:

data gt_grid type grid occurs 0 with header line.

data lt_rows type lvc_t_row.

call method gt_grid-grid->get_selected_rows

importing et_index_rows = lt_rowd.

But when I am compiling, the compiler is telling me gt_grid is not a structure and it does not have a component grid.

So what seems to be the problem?

Basically what i want to do is to get the selected rows from a grid, any ideas on how to do this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
433

Refer this code

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.

2 REPLIES 2
Read only

Former Member
0 Likes
433

Hi,

The get_selected_rows method is in the cl_gui_alv_grid object.

Refer to this sample code:

DATA: w_grid TYPE REF TO cl_gui_alv_grid.

DATA ls_trows TYPE lvc_t_row.

DATA ls_row TYPE lvc_s_row.

DATA:lw_valid TYPE char1.

CALL METHOD w_grid->check_changed_data

IMPORTING

e_valid = lw_valid.

IF sy-subrc EQ 0.

"ignore

ENDIF.

CALL METHOD w_grid->refresh_table_display.

IF sy-subrc EQ 0.

"ignore

ENDIF.

CALL METHOD w_grid->get_selected_rows

IMPORTING

et_index_rows = ls_trows.

IF sy-subrc EQ 0.

"ignore

ENDIF.

Award points if helpful.

Regards,

LM

Read only

Former Member
0 Likes
434

Refer this code

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.