Skip to Content
author's profile photo Former Member
Former Member

Event capturing in OOP ALV

Hi

I want that when user doubleclicks on the any row of alv, the row value should be taken to some workarea.If possible provide some code.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 18, 2007 at 04:05 PM

    Here is a sample program. You need to handle the event DOUBLE_CLICK by using a local event handler class.

    
    REPORT ZRICH_0001.
    
    TABLES: MARA.
    
    DATA: BEGIN OF I_ALV OCCURS 0,
          MATNR TYPE MARA-MATNR,
          MAKTX TYPE MAKT-MAKTX,
          END OF I_ALV.
    
    ***********************************************************************
    *       CLASS cl_event_receiver DEFINITION      Handles Double Click
    ***********************************************************************
    CLASS CL_EVENT_RECEIVER DEFINITION.
      PUBLIC SECTION.
        METHODS HANDLE_DOUBLE_CLICK
          FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
          IMPORTING E_ROW E_COLUMN.
      PRIVATE SECTION.
    ENDCLASS.
    
    ***********************************************************************
    *       CLASS CL_EVENT_RECEIVER IMPLEMENTATION    Handles Double Click
    ***********************************************************************
    CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
      METHOD HANDLE_DOUBLE_CLICK.
        PERFORM DRILL_DOWN USING E_ROW-INDEX.
      ENDMETHOD.
    ENDCLASS.
    
    
    DATA: ALV_CONTAINER  TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    DATA: EVENT_RECEIVER TYPE REF TO CL_EVENT_RECEIVER.
    DATA: ALV_GRID       TYPE REF TO CL_GUI_ALV_GRID.
    DATA: FIELDCAT  TYPE LVC_T_FCAT.
    
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
    SELECTION-SCREEN END OF BLOCK B1.
    
    START-OF-SELECTION.
    
      PERFORM GET_DATA.
      CALL SCREEN 100.
    
    ************************************************************************
    *      Module  status_0100  OUTPUT
    ************************************************************************
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS '0100'.
      SET TITLEBAR '0100'.
    
    * Create Controls
      CREATE OBJECT ALV_CONTAINER
             EXPORTING
                   CONTAINER_NAME    = 'ALV_CONTAINER'.
    
      CREATE OBJECT ALV_GRID
             EXPORTING
                   I_PARENT          =  ALV_CONTAINER.
    
    *  Create Event Receiver
      CREATE OBJECT EVENT_RECEIVER.
    
    *  ALV Specific. Data selection.
    *  Populate Field Catalog
      PERFORM GET_FIELDCATALOG.
    
    
      CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
          CHANGING
               IT_OUTTAB       = I_ALV[]
               IT_FIELDCATALOG = FIELDCAT[].
    
    *   handler for ALV grid
      SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR ALV_GRID.
    
    ENDMODULE.
    
    ************************************************************************
    *      Module  USER_COMMAND_0100  INPUT
    ************************************************************************
    MODULE USER_COMMAND_0100 INPUT.
    
      CASE SY-UCOMM.
        WHEN 'BACK' OR 'CANC'.
          IF NOT ALV_CONTAINER IS INITIAL.
            CALL METHOD ALV_CONTAINER->FREE.
            CLEAR: ALV_CONTAINER.
            FREE : ALV_CONTAINER.
          ENDIF.
          IF SY-SUBRC = 0.
            SET SCREEN 0.
            LEAVE SCREEN.
          ELSE.
            LEAVE PROGRAM.
          ENDIF.
        WHEN 'EXIT'.
          IF NOT ALV_CONTAINER IS INITIAL.
            CALL METHOD ALV_CONTAINER->FREE.
            CLEAR: ALV_CONTAINER.
            FREE : ALV_CONTAINER.
          ENDIF.
          LEAVE PROGRAM.
      ENDCASE.
    
    ENDMODULE.
    
    ************************************************************************
    * FORM GET_DATA
    ************************************************************************
    FORM GET_DATA.
    
      SELECT * INTO CORRESPONDING FIELDS OF TABLE I_ALV
            FROM MARA
              INNER JOIN MAKT
                ON MARA~MATNR = MAKT~MATNR
                   WHERE MARA~MATNR IN S_MATNR
                     AND MAKT~SPRAS = SY-LANGU.
    
      SORT I_ALV ASCENDING BY MATNR.
    
    ENDFORM.
    
    ************************************************************************
    *      Form  Get_Fieldcatalog - Set Up Columns/Headers
    ************************************************************************
    FORM GET_FIELDCATALOG.
    
      DATA: LS_FCAT TYPE LVC_S_FCAT.
      REFRESH: FIELDCAT.
    
      CLEAR: LS_FCAT.
      LS_FCAT-REPTEXT    = 'Material Number'.
      LS_FCAT-COLTEXT    = 'Material Number'.
      LS_FCAT-FIELDNAME  = 'MATNR'.
      LS_FCAT-REF_TABLE  = 'I_ALV'.
      LS_FCAT-OUTPUTLEN  = '18'.
      LS_FCAT-COL_POS    = 1.
      APPEND LS_FCAT TO FIELDCAT.
    
      CLEAR: LS_FCAT.
      LS_FCAT-REPTEXT    = 'Material Description'.
      LS_FCAT-COLTEXT    = 'Material Description'.
      LS_FCAT-FIELDNAME  = 'MAKTX'.
      LS_FCAT-REF_TABLE  = 'I_ALV'.
      LS_FCAT-OUTPUTLEN  = '40'.
      LS_FCAT-COL_POS    = 2.
      APPEND LS_FCAT TO FIELDCAT.
    
    ENDFORM.
    
    ************************************************************************
    * DRILL_DOWN
    ************************************************************************
    FORM DRILL_DOWN USING INDEX.
    
      READ TABLE I_ALV INDEX INDEX.
      IF SY-SUBRC = 0.
        SET PARAMETER ID 'MAT' FIELD I_ALV-MATNR.
        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
        IF NOT ALV_CONTAINER IS INITIAL.
          CALL METHOD ALV_CONTAINER->FREE.
          CLEAR: ALV_CONTAINER.
          FREE : ALV_CONTAINER.
        ENDIF.
      ENDIF.
    
    ENDFORM.
    
    

    Regards,

    Rich Heilman

    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.