Application Development 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: 

Double click event of alv grid control

Former Member
0 Kudos

Hi everyone

I have a screen on which I have placed two ALV grid controls. Each one contains (different) summary data and I would like to allow the user to double click on either grid to open a screen that contains detail information based on the row they double-clicked on. I have managed to do all of this including setting up event handler methods etc. However, the problem I have is that when the double_click event of the cl_gui_alv_grid class is triggered, the detail screen will always display data that is linked to the second grid. I have stepped through the debugger and it looks as if both grids receive the double_click event in sequence - which makes sense. I have tried various approaches such as creating sub-classes of cl_gui_alv_grid but of course they always inherit the double_click event and their methods get triggered when the event happens. I wonder if there is a way of identifying which grid instance was double-clicked and using this within the event handler logic? Alternatively, this could be an insane way of approaching the problem! Either way, any help would be greatly appreciated.

Kind regards

Andy

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

REPORT  ZTEST1234    MESSAGE-ID ZZ                           .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: L_VALID TYPE C,
      V_FLAG,
      V_DATA_CHANGE,
      V_ROW TYPE LVC_S_ROW,
      V_COLUMN TYPE LVC_S_COL,
      V_ROW_NUM TYPE LVC_S_ROID.
DATA: OK_CODE LIKE SY-UCOMM,
      SAVE_OK LIKE SY-UCOMM,
      G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
      GS_LAYOUT TYPE LVC_S_LAYO.

DATA:BEGIN OF  ITAB OCCURS 0,
     VBELN LIKE LIKP-VBELN,
     POSNR LIKE LIPS-POSNR,
     COMISN(10),
     BOX(1),
     CELLCOLOR TYPE LVC_T_SCOL, "required for color
     DROP(20),
     HANDLE_STYLE TYPE LVC_T_STYL,
     END OF ITAB.
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION .
  PUBLIC SECTION .
    METHODS:
**Hot spot Handler
    HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                      IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Handler to Check the Data Change
    HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
                         OF CL_GUI_ALV_GRID
                         IMPORTING ER_DATA_CHANGED
                                   E_ONF4
                                   E_ONF4_BEFORE
                                   E_ONF4_AFTER,
**Double Click Handler
[code]    HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                     IMPORTING E_ROW E_COLUMN ES_ROW_NO.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

*Handle Hotspot Click

METHOD HANDLE_HOTSPOT_CLICK .

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW_ID.

V_COLUMN = E_COLUMN_ID.

V_ROW_NUM = ES_ROW_NO.

MESSAGE I000 WITH V_ROW 'clicked'.

ENDMETHOD. "lcl_event_handler

*Handle Double Click

 METHOD  HANDLE_DOUBLE_CLICK.
    CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
    V_ROW  = E_ROW.
    V_COLUMN = E_COLUMN.
    V_ROW_NUM = ES_ROW_NO.

    IF E_COLUMN = 'VBELN'.
      MESSAGE I000 WITH 'Click on VBELN row number' E_ROW.
      "with this row num you can get the data
    ENDIF.
    IF E_COLUMN = 'POSNR'.

      MESSAGE I000 WITH 'Click on POSNR row number '  E_ROW.
      "with this row num you can get the data
    ENDIF.
  ENDMETHOD.                    "handle_double_click
**Handle Data Change

METHOD HANDLE_DATA_CHANGED.

DATA: X_CHANGE TYPE LVC_S_MODI,

X_FINAL TYPE ITAB,

L_FLAG,

LS_OUTTAB LIKE LINE OF ITAB.

DATA: LS_EDIT TYPE LVC_S_STYL,

LT_EDIT TYPE LVC_T_STYL.

LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO X_CHANGE.

IF X_CHANGE-FIELDNAME = 'DROP' AND X_CHANGE-VALUE = 'S/W ENGINEER'.

LS_EDIT-FIELDNAME = 'COMISN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.

MODIFY ITAB INDEX X_CHANGE-ROW_ID FROM LS_OUTTAB TRANSPORTING

HANDLE_STYLE .

ELSE.

LS_EDIT-FIELDNAME = 'COMISN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.

MODIFY ITAB INDEX X_CHANGE-ROW_ID FROM LS_OUTTAB TRANSPORTING

HANDLE_STYLE .

ENDIF.

ENDLOOP.

CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY

EXCEPTIONS

FINISHED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMETHOD. "HANDLE_DATA_CHANGED

ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

&----


*& Global Definitions

&----


DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1

G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

*- Fieldcatalog for First and second Report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

X_FIELDCAT TYPE LVC_S_FCAT,

LS_VARI TYPE DISVARIANT.

*----


  • START-OF_SELECTION

*----


START-OF-SELECTION.

SELECT VBELN

POSNR

FROM LIPS

UP TO 20 ROWS

INTO CORRESPONDING FIELDS OF TABLE ITAB.

END-OF-SELECTION.

IF NOT ITAB[] IS INITIAL.

CALL SCREEN 100.

ELSE.

MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).

ENDIF.

&----


*& Form CREATE_AND_INIT_ALV

&----


  • text

----


FORM CREATE_AND_INIT_ALV .

DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

CREATE OBJECT G_GRID

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.

GS_LAYOUT-ZEBRA = SPACE.

GS_LAYOUT-CWIDTH_OPT = 'X'.

GS_LAYOUT-NO_ROWMARK = 'X'.

GS_LAYOUT-BOX_FNAME = 'BOX'.

GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

CREATE OBJECT G_HANDLER.

<b>SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.</b>

SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.

DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color

DATA: L_INDEX TYPE SY-TABIX.

"Here i am changing the color of line 1,5,10...

"so you can change the color of font conditionally

LOOP AT ITAB.

L_INDEX = SY-TABIX.

IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.

LS_CELLCOLOR-FNAME = 'VBELN'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

LS_CELLCOLOR-FNAME = 'POSNR'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

ENDIF.

ENDLOOP.

  • setting focus for created grid control

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS

EXPORTING

CONTROL = G_GRID.

  • Build fieldcat and set editable for date and reason code

  • edit enabled. Assign a handle for the dropdown listbox.

PERFORM BUILD_FIELDCAT.

PERFORM SET_DRDN_TABLE.

  • Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.

**Vaiant to save the layout

LS_VARI-REPORT = SY-REPID.

LS_VARI-HANDLE = SPACE.

LS_VARI-LOG_GROUP = SPACE.

LS_VARI-USERNAME = SPACE.

LS_VARI-VARIANT = SPACE.

LS_VARI-TEXT = SPACE.

LS_VARI-DEPENDVARS = SPACE.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

**Calling the Method for ALV output

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

IS_VARIANT = LS_VARI

IS_LAYOUT = GS_LAYOUT

I_SAVE = 'A'

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

  • Set editable cells to ready for input initially

CALL METHOD G_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ENDFORM. "CREATE_AND_INIT_ALV

&----


*& Form EXCLUDE_TB_FUNCTIONS

&----


  • text

----


  • -->PT_EXCLUDE text

----


FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

&----


*& Form build_fieldcat

&----


  • Fieldcatalog

----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-HOTSPOT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Item'(025).

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Drop'(025).

X_FIELDCAT-FIELDNAME = 'DROP'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-DRDN_HNDL = '1'.

X_FIELDCAT-DRDN_ALIAS = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Comissn'(025).

X_FIELDCAT-FIELDNAME = 'COMISN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-EDIT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

ENDFORM. " build_fieldcat

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

**Initializing the grid and calling the fm to Display the O/P

PERFORM CREATE_AND_INIT_ALV.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form SET_DRDN_TABLE

&----


  • text

----


FORM SET_DRDN_TABLE.

DATA:LT_DRAL TYPE LVC_T_DRAL,

LS_DRAL TYPE LVC_S_DRAL.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = 'S/W Engineer'.

LS_DRAL-INT_VALUE = 'S/W Engineer'.

APPEND LS_DRAL TO LT_DRAL.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = 'Manager'.

LS_DRAL-INT_VALUE = 'Manager'.

APPEND LS_DRAL TO LT_DRAL.

**Setting the Drop down table for Reason Code

CALL METHOD G_GRID->SET_DROP_DOWN_TABLE

EXPORTING

IT_DROP_DOWN_ALIAS = LT_DRAL.

ENDFORM. " set_drdn_table[/code]

Regards

vijay

9 REPLIES 9

hymavathi_oruganti
Active Contributor
0 Kudos

SORRY I DIDNT READ UR QUESTION COMPLETELY, IGNORE PREVIOUS ANSWER,

U CAN TRY LIKE BELOW..

THERE IS A METHOD IN CL_ALV_CUSTOM_CONTAINER , <b>SET_FOCUS</b>, U CAN USE THIS METHOD AND SET FOCUS ON THE GRID U WANT AND USE DOUBLE CLICK.

HOPE THIS HELPS

Message was edited by: Hymavathi Oruganti

0 Kudos

Thanks Hymavathi

I had noticed the set_focus method but couldn't quite figure out how I could use it to solve my problem. I kept coming up against the same issue of identifying which grid the user dbl-clicked on. Without knowing that there is no way of setting the focus to it - unless I'm missing something. It would be nice if there were some way of identifying which control currently has the focus - but I can't see anything like that.

Kind regards

Andy

former_member188685
Active Contributor
0 Kudos

REPORT  ZTEST1234    MESSAGE-ID ZZ                           .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: L_VALID TYPE C,
      V_FLAG,
      V_DATA_CHANGE,
      V_ROW TYPE LVC_S_ROW,
      V_COLUMN TYPE LVC_S_COL,
      V_ROW_NUM TYPE LVC_S_ROID.
DATA: OK_CODE LIKE SY-UCOMM,
      SAVE_OK LIKE SY-UCOMM,
      G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
      GS_LAYOUT TYPE LVC_S_LAYO.

DATA:BEGIN OF  ITAB OCCURS 0,
     VBELN LIKE LIKP-VBELN,
     POSNR LIKE LIPS-POSNR,
     COMISN(10),
     BOX(1),
     CELLCOLOR TYPE LVC_T_SCOL, "required for color
     DROP(20),
     HANDLE_STYLE TYPE LVC_T_STYL,
     END OF ITAB.
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION .
  PUBLIC SECTION .
    METHODS:
**Hot spot Handler
    HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                      IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Handler to Check the Data Change
    HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
                         OF CL_GUI_ALV_GRID
                         IMPORTING ER_DATA_CHANGED
                                   E_ONF4
                                   E_ONF4_BEFORE
                                   E_ONF4_AFTER,
**Double Click Handler
[code]    HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                     IMPORTING E_ROW E_COLUMN ES_ROW_NO.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

*Handle Hotspot Click

METHOD HANDLE_HOTSPOT_CLICK .

CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.

V_ROW = E_ROW_ID.

V_COLUMN = E_COLUMN_ID.

V_ROW_NUM = ES_ROW_NO.

MESSAGE I000 WITH V_ROW 'clicked'.

ENDMETHOD. "lcl_event_handler

*Handle Double Click

 METHOD  HANDLE_DOUBLE_CLICK.
    CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
    V_ROW  = E_ROW.
    V_COLUMN = E_COLUMN.
    V_ROW_NUM = ES_ROW_NO.

    IF E_COLUMN = 'VBELN'.
      MESSAGE I000 WITH 'Click on VBELN row number' E_ROW.
      "with this row num you can get the data
    ENDIF.
    IF E_COLUMN = 'POSNR'.

      MESSAGE I000 WITH 'Click on POSNR row number '  E_ROW.
      "with this row num you can get the data
    ENDIF.
  ENDMETHOD.                    "handle_double_click
**Handle Data Change

METHOD HANDLE_DATA_CHANGED.

DATA: X_CHANGE TYPE LVC_S_MODI,

X_FINAL TYPE ITAB,

L_FLAG,

LS_OUTTAB LIKE LINE OF ITAB.

DATA: LS_EDIT TYPE LVC_S_STYL,

LT_EDIT TYPE LVC_T_STYL.

LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO X_CHANGE.

IF X_CHANGE-FIELDNAME = 'DROP' AND X_CHANGE-VALUE = 'S/W ENGINEER'.

LS_EDIT-FIELDNAME = 'COMISN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.

MODIFY ITAB INDEX X_CHANGE-ROW_ID FROM LS_OUTTAB TRANSPORTING

HANDLE_STYLE .

ELSE.

LS_EDIT-FIELDNAME = 'COMISN'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.

MODIFY ITAB INDEX X_CHANGE-ROW_ID FROM LS_OUTTAB TRANSPORTING

HANDLE_STYLE .

ENDIF.

ENDLOOP.

CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY

EXCEPTIONS

FINISHED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMETHOD. "HANDLE_DATA_CHANGED

ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

&----


*& Global Definitions

&----


DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1

G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

*- Fieldcatalog for First and second Report

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

X_FIELDCAT TYPE LVC_S_FCAT,

LS_VARI TYPE DISVARIANT.

*----


  • START-OF_SELECTION

*----


START-OF-SELECTION.

SELECT VBELN

POSNR

FROM LIPS

UP TO 20 ROWS

INTO CORRESPONDING FIELDS OF TABLE ITAB.

END-OF-SELECTION.

IF NOT ITAB[] IS INITIAL.

CALL SCREEN 100.

ELSE.

MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).

ENDIF.

&----


*& Form CREATE_AND_INIT_ALV

&----


  • text

----


FORM CREATE_AND_INIT_ALV .

DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

CREATE OBJECT G_GRID

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.

GS_LAYOUT-ZEBRA = SPACE.

GS_LAYOUT-CWIDTH_OPT = 'X'.

GS_LAYOUT-NO_ROWMARK = 'X'.

GS_LAYOUT-BOX_FNAME = 'BOX'.

GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

CREATE OBJECT G_HANDLER.

<b>SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.</b>

SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.

DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color

DATA: L_INDEX TYPE SY-TABIX.

"Here i am changing the color of line 1,5,10...

"so you can change the color of font conditionally

LOOP AT ITAB.

L_INDEX = SY-TABIX.

IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.

LS_CELLCOLOR-FNAME = 'VBELN'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

LS_CELLCOLOR-FNAME = 'POSNR'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '0'.

LS_CELLCOLOR-COLOR-INV = '1'.

APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.

MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.

ENDIF.

ENDLOOP.

  • setting focus for created grid control

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS

EXPORTING

CONTROL = G_GRID.

  • Build fieldcat and set editable for date and reason code

  • edit enabled. Assign a handle for the dropdown listbox.

PERFORM BUILD_FIELDCAT.

PERFORM SET_DRDN_TABLE.

  • Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.

**Vaiant to save the layout

LS_VARI-REPORT = SY-REPID.

LS_VARI-HANDLE = SPACE.

LS_VARI-LOG_GROUP = SPACE.

LS_VARI-USERNAME = SPACE.

LS_VARI-VARIANT = SPACE.

LS_VARI-TEXT = SPACE.

LS_VARI-DEPENDVARS = SPACE.

CALL METHOD G_GRID->REGISTER_EDIT_EVENT

EXPORTING

I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.

**Calling the Method for ALV output

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

IS_VARIANT = LS_VARI

IS_LAYOUT = GS_LAYOUT

I_SAVE = 'A'

CHANGING

IT_FIELDCATALOG = IT_FIELDCAT

IT_OUTTAB = ITAB[].

  • Set editable cells to ready for input initially

CALL METHOD G_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ENDFORM. "CREATE_AND_INIT_ALV

&----


*& Form EXCLUDE_TB_FUNCTIONS

&----


  • text

----


  • -->PT_EXCLUDE text

----


FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.

APPEND LS_EXCLUDE TO PT_EXCLUDE.

ENDFORM. " EXCLUDE_TB_FUNCTIONS

&----


*& Form build_fieldcat

&----


  • Fieldcatalog

----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-HOTSPOT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Item'(025).

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Drop'(025).

X_FIELDCAT-FIELDNAME = 'DROP'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-DRDN_HNDL = '1'.

X_FIELDCAT-DRDN_ALIAS = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Comissn'(025).

X_FIELDCAT-FIELDNAME = 'COMISN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-EDIT = 'X'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

ENDFORM. " build_fieldcat

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

**Initializing the grid and calling the fm to Display the O/P

PERFORM CREATE_AND_INIT_ALV.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form SET_DRDN_TABLE

&----


  • text

----


FORM SET_DRDN_TABLE.

DATA:LT_DRAL TYPE LVC_T_DRAL,

LS_DRAL TYPE LVC_S_DRAL.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = 'S/W Engineer'.

LS_DRAL-INT_VALUE = 'S/W Engineer'.

APPEND LS_DRAL TO LT_DRAL.

LS_DRAL-HANDLE = '1'.

LS_DRAL-VALUE = 'Manager'.

LS_DRAL-INT_VALUE = 'Manager'.

APPEND LS_DRAL TO LT_DRAL.

**Setting the Drop down table for Reason Code

CALL METHOD G_GRID->SET_DROP_DOWN_TABLE

EXPORTING

IT_DROP_DOWN_ALIAS = LT_DRAL.

ENDFORM. " set_drdn_table[/code]

Regards

vijay

0 Kudos

Thanks Vijay

I'll have a play around with the logic you have here and see if I can get it to work for my situtation.

Kind regards

Andrew

0 Kudos

Hi andrew,

there is a way to capture the row, column info which you have clicked.

and now you have row info,column info,

based on these you can do one thing..

these info you get from double click event.

  IF NOT V_ROW IS INITIAL
   AND NOT V_COLUMN IS INITIAL
   AND NOT V_ROW_NUM IS INITIAL.
    CALL METHOD G_GRID->SET_CURRENT_CELL_VIA_ID
      EXPORTING
        IS_ROW_ID    = V_ROW
        IS_COLUMN_ID = V_COLUMN
        IS_ROW_NO    = V_ROW_NUM.

  ENDIF.

try this , this will set the focus on which you have clicked.

Regards

vijay

0 Kudos

In your event handler you can specify 'sender' parameter:

METHOD  handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column sender.

Then in your method implementation you have access to sender object (alv instance)

0 Kudos

Thanks Thomasz, that seems to have done it - fantastic!

former_member182670
Contributor
0 Kudos

Why don't you create two objects of event handler class and register one of them for events of one grid?

0 Kudos

I will give this a go but I think that the same problem will exist - ie that regardless of which grid is dbl-clicked, anything which is waiting for the double_click event to be fired will still detect the event.

Many thanks

Andy