Skip to Content

ALV Sort then Dbl Click - get wrong row

Hi,

I have an internal table that populates an ALV grid. When the user doubleclicks a row, my method HANDLE_DOUBLE_CLICK returns the e_row-index value from the ALV Grid. I use this index value to read the internal table, then retrieve additional data.

My problem is the user may sort the ALV grid before double clicking on a line. If this happens my internal table is not sorted to match the ALV grid, so reading the internal table with the e_row-index value returns the wrong information.

When the double click event occurs, is it possible to capture the value in column 1 instead of a value for e_row-index? or is there a way to tell me which Sort (or other event) was selected and on which column it was performed?

Thanks

MPersson

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 15, 2011 at 04:26 AM

    Hi,

    I am attaching The code which will retrieve E_Row and E_Column.

    REPORT  ZALVGRID_PG.
    TABLES: SSCRFIELDS.
    
    DATA: V_BELNR TYPE RBKP-BELNR.
    
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: IRNO FOR V_BELNR.
    PARAMETERS: P_GJAHR TYPE RBKP-GJAHR.
    SELECTION-SCREEN END OF BLOCK B1.
    
    DATA: WA TYPE ZALVGRID_DISPLAY,
          ITAB TYPE STANDARD TABLE OF ZALVGRID_DISPLAY.
    
    DATA: IDENTITY TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    
    DATA: GRID TYPE REF TO CL_GUI_ALV_GRID.
    
    DATA: L_IDENTITY TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    
    DATA: L_TREE TYPE REF TO CL_GUI_ALV_TREE_SIMPLE.
    
    TYPE-POOLS: SLIS,SDYDO.
    
    DATA: L_LOGO TYPE SDYDO_VALUE,
          L_LIST TYPE SLIS_T_LISTHEADER.
    
    END-OF-SELECTION.
    
    
    CLASS CL_LC DEFINITION.
      PUBLIC SECTION.
        METHODS: DC FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW E_COLUMN.
    ENDCLASS.
    
    CLASS CL_LC IMPLEMENTATION.
      METHOD DC.
        DATA: WA1 TYPE ZALVGRID_DISPLAY.
        READ TABLE ITAB INTO WA1 INDEX E_ROW-INDEX.
        BREAK-POINT.
        SET PARAMETER ID 'BLN' FIELD WA1-BELNR.
        CALL TRANSACTION 'FB02'.
      ENDMETHOD.                    "DC
    ENDCLASS.
    
    
    
    DATA: OBJ_CL TYPE REF TO CL_LC.
    
    START-OF-SELECTION.
      PERFORM SELECT_DATA.
      IF SY-SUBRC = 0.
        CALL SCREEN 100.
    
      ELSE.
        MESSAGE E000(0) WITH 'DATA NOT FOUND'.
      ENDIF.
    
      INCLUDE ZALVGRID_PG_STATUS_0100O01.
    
      INCLUDE ZALVGRID_PG_LOGOSUBF01.
    
      INCLUDE ZALVGRID_PG_SELECT_DATAF01.
    
    INCLUDE ZALVGRID_PG_USER_COMMAND_01I01.
    
    *----------------------------------------------------------------------*
    ***INCLUDE ZALVGRID_PG_STATUS_0100O01 .
    *----------------------------------------------------------------------*
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'AB'.
    *  SET TITLEBAR 'xxx'.
    
      IF IDENTITY IS INITIAL.
        CREATE OBJECT IDENTITY
        EXPORTING
          CONTAINER_NAME = 'ALVCONTROL'.
        CREATE OBJECT GRID
        EXPORTING
          I_PARENT = IDENTITY.
    
        CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
          EXPORTING
    *        I_BUFFER_ACTIVE               =
    *        I_BYPASSING_BUFFER            =
    *        I_CONSISTENCY_CHECK           =
             I_STRUCTURE_NAME              = 'ZALVGRID_DISPLAY'
    *
    *        IS_VARIANT                    =
    *        I_SAVE                        =
    *        I_DEFAULT                     = 'X'
    *        IS_LAYOUT                     =
    *        IS_PRINT                      =
    *        IT_SPECIAL_GROUPS             =
    *        IT_TOOLBAR_EXCLUDING          =
    *        IT_HYPERLINK                  =
    *        IT_ALV_GRAPHICS               =
    *        IT_EXCEPT_QINFO               =
    *        IR_SALV_ADAPTER               =
          CHANGING
            IT_OUTTAB                     = ITAB.
    *        IT_FIELDCATALOG               =
    *        IT_SORT                       =
    *        IT_FILTER                     =
    *      EXCEPTIONS
    *        INVALID_PARAMETER_COMBINATION = 1
    *        PROGRAM_ERROR                 = 2
    *        TOO_MANY_LINES                = 3
    *        others                        = 4
                .
        IF SY-SUBRC <> 0.
    *     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        CREATE OBJECT OBJ_CL.
        SET HANDLER OBJ_CL->DC FOR GRID.
        ENDIF.
    
        IF L_IDENTITY IS INITIAL.
          CREATE OBJECT L_IDENTITY
          EXPORTING
            CONTAINER_NAME = 'LOGO'
            .
          CREATE OBJECT L_TREE
          EXPORTING
            I_PARENT = L_IDENTITY.
    
          PERFORM LOGOSUB USING L_LOGO.
          CALL METHOD L_TREE->CREATE_REPORT_HEADER
            EXPORTING
              IT_LIST_COMMENTARY    = L_LIST
              I_LOGO                = L_LOGO.
    
    *          I_BACKGROUND_ID       =
    *          I_SET_SPLITTER_HEIGHT =
    *          I_MODEL_MODE          =
          ENDIF    .
    
    
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    
    *----------------------------------------------------------------------*
    ***INCLUDE ZALVGRID_PG_LOGOSUBF01 .
    *----------------------------------------------------------------------*
    *&---------------------------------------------------------------------*
    *&      Form  LOGOSUB
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_L_LOGO  text
    *----------------------------------------------------------------------*
    FORM LOGOSUB  USING    P_L_LOGO.
      P_L_LOGO = 'ERPLOGO'.
    
    ENDFORM.                    " LOGOSUB
    
    
    
    *----------------------------------------------------------------------*
    ***INCLUDE ZALVGRID_PG_SELECT_DATAF01 .
    *----------------------------------------------------------------------*
    *&---------------------------------------------------------------------*
    *&      Form  SELECT_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM SELECT_DATA .
    
      SELECT RBKP~BELNR
             RBKP~BLDAT
             RSEG~BUZEI
             RSEG~MATNR
             INTO TABLE ITAB
             FROM RBKP INNER JOIN RSEG
        ON RBKP~BELNR = RSEG~BELNR
        WHERE RBKP~BELNR IN IRNO
        AND RBKP~GJAHR = P_GJAHR.
    
    ENDFORM.                    " SELECT_DATA
    
    
    *----------------------------------------------------------------------*
    ***INCLUDE ZALVGRID_PG_USER_COMMAND_01I01 .
    *----------------------------------------------------------------------*
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'EXIT'.
          LEAVE PROGRAM.
        WHEN 'CANCEL'.
           EXIT.
           ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT

    Edited by: pavankumar.g on Dec 15, 2011 5:27 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 14, 2011 at 03:30 PM

    u can use method refresh_table_display before calling the double_click event

            
    CALL METHOD r_grid1->refresh_table_display.
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.