Skip to Content
avatar image
Former Member

Handle CLICK_ROW_COL in class CL_GUI_ALV_GRID

Hi,

I want to handle single click event in ALV Grid.

There is one protected event CLICK_ROW_COL in class CL_GUI_ALV_GRID.

I created ZCL_GUI_ALV_GRID in se24 and defined one event ZCLICK_ROW_COL in it.

My query is how to attach that event to AVL GRID....I mean to say how that event will be triggered.

Please suggest.

Regards

Prasoon

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Aug 20, 2007 at 09:56 AM

    Hi,

    u can use the event HOTSPOT_CLICK of class CL_GUI_ALV_GRID.

    check this sample code.

    REPORT ztest440.

    TABLES : mara.

    TYPES: BEGIN OF t_mara,

    matnr TYPE mara-matnr,

    lvorm TYPE mara-lvorm,

    mtart TYPE mara-mtart,

    mbrsh TYPE mara-mbrsh,

    matkl TYPE mara-matkl,

    meins TYPE mara-meins,

    brgew TYPE mara-brgew,

    ntgew TYPE mara-ntgew,

    gewei TYPE mara-gewei,

    END OF t_mara.

    TYPES: BEGIN OF t_equk,

    matnr TYPE equk-matnr,

    werks TYPE equk-werks,

    bdatu TYPE equk-bdatu,

    vdatu TYPE equk-vdatu,

    qunum TYPE equk-qunum,

    END OF t_equk.

    CLASS : lcl_alv_grid DEFINITION DEFERRED.

    DATA : gi_mara TYPE STANDARD TABLE OF t_mara,

    gi_equk TYPE STANDARD TABLE OF t_equk,

    gs_mara TYPE t_mara,

    gs_equk TYPE t_equk.

    *-- Global data definitions for ALV

    *--- ALV Grid instance reference

    DATA : gw_alvgrid TYPE REF TO cl_gui_alv_grid,

    gw_alvgrid1 TYPE REF TO cl_gui_alv_grid .

    *--- Custom container instance reference

    DATA gw_container TYPE REF TO cl_gui_custom_container.

    DATA gw_event_handler TYPE REF TO lcl_alv_grid.

    DATA gw_event_handler1 TYPE REF TO lcl_alv_grid.

    DATA gw_container1 TYPE REF TO cl_gui_custom_container.

    *--- Field catalog table

    DATA : gi_fieldcat TYPE lvc_t_fcat,

    gi_fieldcat1 TYPE lvc_t_fcat,

    gs_fieldcat TYPE lvc_s_fcat,

    gs_fieldcat1 TYPE lvc_s_fcat.

    *--- Layout structure

    DATA : gs_layout TYPE lvc_s_layo,

    gs_layout1 TYPE lvc_s_layo.

    ----


    • CLASS lcl_alv_grid DEFINITION

    ----


    *

    ----


    CLASS lcl_alv_grid DEFINITION.

    PUBLIC SECTION.

    METHODS :

    • Handle_double_click

    handle_double_click

    FOR EVENT double_click OF cl_gui_alv_grid

    IMPORTING e_row e_column,

    • Handle_double_click

    handle_onf4

    FOR EVENT onf4 OF cl_gui_alv_grid

    IMPORTING e_fieldname,

    • Handle_double_click

    handle_hotspot_click

    FOR EVENT hotspot_click OF cl_gui_alv_grid

    IMPORTING e_row_id.

    PRIVATE SECTION.

    ENDCLASS. " lcl_alv_grid DEFINITION

    ----


    • CLASS LCL_ALV_GRID IMPLEMENTATION *

    ----


    CLASS lcl_alv_grid IMPLEMENTATION.

    ----


    • METHOD handle_double_click *

    ----


    METHOD handle_double_click.

    READ TABLE gi_mara INTO gs_mara INDEX e_row.

    IF sy-subrc = 0.

    SELECT matnr

    werks

    bdatu

    vdatu

    qunum

    FROM equk

    INTO TABLE gi_equk

    WHERE matnr = gs_mara-matnr.

    IF sy-dbcnt NE 0.

    SORT gi_equk BY matnr werks bdatu.

    ENDIF.

    CALL SCREEN 0002.

    ENDIF.

    ENDMETHOD. "handle_double_click

    ----


    • METHOD handle_onf4 *

    ----


    METHOD handle_onf4.

    PERFORM f4_help USING e_fieldname.

    ENDMETHOD. "handle_double_click

    ----


    • METHOD handle_double_click *

    ----


    METHOD handle_hotspot_click.

    READ TABLE gi_mara INTO gs_mara INDEX e_row_id.

    IF sy-subrc = 0.

    SELECT matnr

    werks

    bdatu

    vdatu

    qunum

    FROM equk

    INTO TABLE gi_equk

    WHERE matnr = gs_mara-matnr.

    IF sy-dbcnt NE 0.

    SORT gi_equk BY matnr werks bdatu.

    ENDIF.

    CALL SCREEN 0002.

    ENDIF.

    ENDMETHOD. "handle_hotspot_click

    ENDCLASS. " lcl_alv_grid IMPLEMENTATION

    ----


    • SELECTION SCREEN DEFINITION *

    ----


    SELECTION-SCREEN BEGIN OF BLOCK b1.

    SELECT-OPTIONS : s_matnr FOR mara-matnr NO INTERVALS,

    s_mtart FOR mara-mtart NO INTERVALS.

    SELECTION-SCREEN END OF BLOCK b1.

    ----


    • START-OF-SELECTION *

    ----


    START-OF-SELECTION.

    SELECT matnr

    lvorm

    mtart

    mbrsh

    matkl

    meins

    brgew

    ntgew

    gewei

    FROM mara

    INTO TABLE gi_mara

    WHERE matnr IN s_matnr

    AND mtart IN s_mtart.

    IF sy-dbcnt NE 0.

    SORT gi_mara BY matnr.

    ENDIF.

    CALL SCREEN 0001.

    &----


    *& Module STATUS_0001 OUTPUT

    &----


    • text

    ----


    MODULE status_0001 OUTPUT.

    SET PF-STATUS '0001'.

    SET TITLEBAR '001'.

    PERFORM build_alv_display.

    ENDMODULE. " STATUS_0001 OUTPUT

    &----


    *& Module USER_COMMAND_0001 INPUT

    &----


    • text

    ----


    MODULE user_command_0001 INPUT.

    CASE sy-ucomm.

    WHEN 'EXIT'.

    LEAVE TO SCREEN 0.

    WHEN 'SAVE'.

    LEAVE TO SCREEN 0.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0001 INPUT

    &----


    *& Form build_alv_display

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM build_alv_display .

    PERFORM build_fieldcat.

    PERFORM build_layout.

    PERFORM create_alv_grid.

    PERFORM display_alv_grid.

    ENDFORM. " build_alv_display

    &----


    *& Form build_fieldcat

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM build_fieldcat .

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MATNR'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Material Number'.

    gs_fieldcat-outputlen = '18'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '1'.

    gs_fieldcat-hotspot = 'X'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'LVORM'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Deletion'.

    gs_fieldcat-outputlen = '8'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '2'.

    gs_fieldcat-checkbox = 'X'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MTART'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Material Type'.

    gs_fieldcat-outputlen = '13'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '3'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MBRSH'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Industry sector'.

    gs_fieldcat-outputlen = '15'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '4'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MATKL'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Material group'.

    gs_fieldcat-outputlen = '14'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '5'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MEINS'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Base Unit of Measure'.

    gs_fieldcat-outputlen = '20'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '6'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'BRGEW'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Gross weight'.

    gs_fieldcat-outputlen = '13'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '7'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'NTGEW'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Net weight'.

    gs_fieldcat-outputlen = '13'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '8'.

    APPEND gs_fieldcat TO gi_fieldcat.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'GEWEI'.

    gs_fieldcat-tabname = 'MARA'.

    gs_fieldcat-coltext = 'Weight Unit'.

    gs_fieldcat-outputlen = '11'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '9'.

    APPEND gs_fieldcat TO gi_fieldcat.

    ENDFORM. " build_fieldcat

    &----


    *& Form build_layout

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM build_layout .

    gs_layout-sel_mode = 'A'.

    gs_layout-edit = ' '.

    gs_layout-no_toolbar = ' '.

    gs_layout-grid_title = 'Material Data'.

    gs_layout-no_headers = ' '.

    gs_layout-weblook = 'X'.

    ENDFORM. " build_layout

    &----


    *& Form create_alv_grid

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM create_alv_grid .

    IF gw_container IS INITIAL.

    CREATE OBJECT gw_container

    EXPORTING

    container_name = 'CC_ALV'.

    • Display ALV grid

    IF gw_alvgrid IS INITIAL.

    CREATE OBJECT gw_alvgrid

    EXPORTING

    i_parent = gw_container.

    ENDIF.

    ENDIF.

    IF gw_event_handler IS INITIAL.

    CREATE OBJECT gw_event_handler.

    SET HANDLER gw_event_handler->handle_double_click

    FOR gw_alvgrid.

    SET HANDLER gw_event_handler->handle_onf4

    FOR gw_alvgrid.

    SET HANDLER gw_event_handler->handle_hotspot_click

    FOR gw_alvgrid.

    ENDIF.

    ENDFORM. " create_alv_grid

    &----


    *& Form display_alv_grid

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM display_alv_grid .

    CALL METHOD gw_alvgrid->set_table_for_first_display

    EXPORTING

    i_buffer_active = ' '

    i_bypassing_buffer = ' '

    i_structure_name = 'T_MARA'

    is_layout = gs_layout

    CHANGING

    it_outtab = gi_mara[]

    it_fieldcatalog = gi_fieldcat[]

    EXCEPTIONS

    OTHERS = 0.

    ENDFORM. " display_alv_grid

    *&----


    *

    *& Module STATUS_0002 OUTPUT

    *&----


    *

    • text

    *----


    *

    MODULE status_0002 OUTPUT.

    SET PF-STATUS '0002'.

    SET TITLEBAR '002'.

    PERFORM build_alv_display1.

    ENDMODULE. " STATUS_0002 OUTPUT

    *&----


    *

    *& Module USER_COMMAND_0002 INPUT

    *&----


    *

    • text

    *----


    *

    MODULE user_command_0002 INPUT.

    CASE sy-ucomm.

    WHEN 'EXIT'.

    LEAVE TO SCREEN 0.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0002 INPUT

    *&----


    *

    *& Form build_alv_display1

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM build_alv_display1 .

    PERFORM build_fieldcat1.

    PERFORM build_layout1.

    PERFORM create_alv_grid1.

    PERFORM display_alv_grid1.

    ENDFORM. " build_alv_display1

    *&----


    *

    *& Form build_fieldcat2

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM build_fieldcat1.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'MATNR'.

    gs_fieldcat-tabname = 'EQUK'.

    gs_fieldcat-coltext = 'Material Number'.

    gs_fieldcat-outputlen = '18'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '1'.

    gs_fieldcat-f4availabl = 'X'.

    APPEND gs_fieldcat TO gi_fieldcat1.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'WERKS'.

    gs_fieldcat-tabname = 'EQUK'.

    gs_fieldcat-coltext = 'Plant'.

    gs_fieldcat-outputlen = '4'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '2'.

    APPEND gs_fieldcat TO gi_fieldcat1.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'BDATU'.

    gs_fieldcat-tabname = 'EQUK'.

    gs_fieldcat-coltext = 'Valid Untill'.

    gs_fieldcat-outputlen = '12'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '3'.

    APPEND gs_fieldcat TO gi_fieldcat1.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'VDATU'.

    gs_fieldcat-tabname = 'EQUK'.

    gs_fieldcat-coltext = 'Valid From'.

    gs_fieldcat-outputlen = '10'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '4'.

    APPEND gs_fieldcat TO gi_fieldcat1.

    CLEAR gs_fieldcat.

    gs_fieldcat-fieldname = 'QUNUM'.

    gs_fieldcat-tabname = 'EQUK'.

    gs_fieldcat-coltext = 'Quota'.

    gs_fieldcat-outputlen = '10'.

    gs_fieldcat-edit = ' '.

    gs_fieldcat-just = 'C'.

    gs_fieldcat-col_pos = '5'.

    APPEND gs_fieldcat TO gi_fieldcat1.

    ENDFORM. " build_fieldcat2

    *&----


    *

    *& Form build_layout2

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM build_layout1.

    gs_layout1-sel_mode = 'A'.

    gs_layout1-edit = ' '.

    gs_layout1-no_toolbar = ' '.

    gs_layout1-grid_title = 'Quota Header Data'.

    gs_layout1-no_headers = ' '.

    ENDFORM. " build_layout1

    *&----


    *

    *& Form create_alv_grid2

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM create_alv_grid1.

    IF gw_container1 IS INITIAL.

    CREATE OBJECT gw_container1

    EXPORTING

    container_name = 'CC_ALV1'.

    • Display ALV grid

    IF gw_alvgrid1 IS INITIAL.

    CREATE OBJECT gw_alvgrid1

    EXPORTING

    i_parent = gw_container1.

    ENDIF.

    ENDIF.

    IF gw_event_handler1 IS INITIAL.

    CREATE OBJECT gw_event_handler1.

    SET HANDLER gw_event_handler1->handle_onf4

    FOR gw_alvgrid1.

    ENDIF.

    ENDFORM. " create_alv_grid1

    *&----


    *

    *& Form display_alv_grid2

    *&----


    *

    • text

    *----


    *

    • --> p1 text

    • <-- p2 text

    *----


    *

    FORM display_alv_grid1 .

    DATA : li_f4 TYPE lvc_t_f4,

    ls_f4 TYPE lvc_s_f4.

    CALL METHOD gw_alvgrid1->set_table_for_first_display

    EXPORTING

    i_buffer_active = ' '

    i_bypassing_buffer = ' '

    i_structure_name = 'T_EQUK'

    is_layout = gs_layout1

    CHANGING

    it_outtab = gi_equk[]

    it_fieldcatalog = gi_fieldcat1[]

    EXCEPTIONS

    OTHERS = 0.

    IF li_f4[] IS INITIAL.

    MOVE 'MATNR' TO ls_f4-fieldname.

    MOVE 'X' TO ls_f4-register.

    MOVE 'X' TO ls_f4-getbefore.

    APPEND ls_f4 TO li_f4.

    CLEAR ls_f4.

    CALL METHOD gw_alvgrid1->register_f4_for_fields

    EXPORTING

    it_f4 = li_f4.

    ENDIF.

    ENDFORM. " display_alv_grid1

    &----


    *& Form f4_help

    &----


    • text

    ----


    • -->P_FIELDNAME text

    ----


    FORM f4_help USING p_fieldname.

    TYPES : BEGIN OF t_values,

    matnr TYPE mara-matnr,

    END OF t_values.

    DATA : li_fields TYPE TABLE OF dfies,

    li_select_values TYPE TABLE OF ddshretval,

    li_values TYPE TABLE OF t_values,

    ls_fields TYPE dfies,

    ls_values TYPE t_values.

    REFRESH : li_fields,

    li_select_values.

    SELECT matnr

    FROM equk

    INTO TABLE li_values.

    CASE p_fieldname.

    WHEN 'MATNR'.

    ls_fields-tabname = 'EQUK'.

    ls_fields-fieldname = 'MATNR'.

    APPEND ls_fields TO li_fields.

    CLEAR ls_fields.

    SORT li_values BY matnr.

    DELETE ADJACENT DUPLICATES FROM li_values COMPARING matnr.

    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

    retfield = 'MATNR'

    TABLES

    value_tab = li_values

    field_tab = li_fields

    return_tab = li_select_values.

    IF sy-subrc = 0.

    • LOOP AT li_select_values WHERE fieldname = 'MATNR'.

    • clear gs_mara.

    • gs_mara in

    ENDIF.

    ENDCASE.

    ENDFORM. " f4_help

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 10:11 AM

    Hi,

    just heck similar to ur reqmt. i had to use doubleclick event of ALV. this is how i used it.. This is a simple program which shows records from KNA1 table in LAV and on double clicking a particular record it goes to transaction XD02.

    ----


    • Data Declaration

    ----


    DATA: CC TYPE SCRFNAME VALUE 'CC',

    GRID TYPE REF TO CL_GUI_ALV_GRID,

    CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

    DATA: I_KNA1 TYPE TABLE OF KNA1.

    ----


    • CLASS sab DEFINITION

    ----


    CLASS SAB DEFINITION.

    PUBLIC SECTION.

    <b>METHODS: DCEVENT FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW.</b>ENDCLASS. "sab DEFINITION

    ----


    • CLASS sab IMPLEMENTATION

    ----


    CLASS SAB IMPLEMENTATION.

    <b>METHOD DCEVENT.

    DATA: WA_KNA1 LIKE LINE OF I_KNA1..

    READ TABLE I_KNA1 INDEX E_ROW-INDEX INTO WA_KNA1.

    SET PARAMETER ID 'KUN' FIELD WA_KNA1-KUNNR.

    CALL TRANSACTION 'XD02' AND SKIP FIRST SCREEN.

    ENDMETHOD. "dcevent</b>ENDCLASS. "sab IMPLEMENTATION

    ----


    • Start of selection

    ----


    START-OF-SELECTION.

    DATA: OBJ TYPE REF TO SAB.

    PERFORM POPULATE_TABLE.

    END-OF-SELECTION.

    CALL SCREEN 100.

    &----


    *& Module USER_COMMAND_0100 INPUT

    &----


    • PAI module

    ----


    MODULE USER_COMMAND_0100 INPUT.

    CASE SY-UCOMM.

    WHEN 'BACK' OR 'LEAV' OR 'CANC' .

    LEAVE PROGRAM.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0100 INPUT

    &----


    *& Module STATUS_0100 OUTPUT

    &----


    • PBO module

    ----


    MODULE STATUS_0100 OUTPUT.

    SET PF-STATUS 'ZSAB1'.

    • SET TITLEBAR 'xxx'.

    IF GRID IS INITIAL.

    CREATE OBJECT CONTAINER

    EXPORTING

    CONTAINER_NAME = CC.

    CREATE OBJECT GRID

    EXPORTING

    I_PARENT = CONTAINER.

    CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY

    EXPORTING

    I_STRUCTURE_NAME = 'KNA1'

    CHANGING

    IT_OUTTAB = I_KNA1.

    CREATE OBJECT OBJ.

    SET HANDLER OBJ->DCEVENT FOR GRID.

    ENDIF.

    ENDMODULE. " STATUS_0100 OUTPUT

    &----


    *& Form POPULATE_TABLE

    &----


    • POPULATE TABLE I_KNA1

    ----


    FORM POPULATE_TABLE .

    SELECT * FROM KNA1 UP TO 10 ROWS INTO TABLE I_KNA1.

    ENDFORM. " POPULATE_TABLE

    Add comment
    10|10000 characters needed characters exceeded