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: 

How to set ALV grid cell a value ?

Former Member
0 Kudos

Hello,

please, answer me.

I should edit a values of listed table in a CL_CRM_ALV_GRID like it was edited by a user. I tried to raise an event, but it was not working. I hoped that I can fill the list table and than set the ALV grid to state edited, but it seem that I am going totaly wrong way.

9 REPLIES 9

former_member188685
Active Contributor
0 Kudos

Hi,

that class is not in R3 , what event you are raising .

normally we go for cl_gui_alv_grid, here we will raise data_changed event. please clarify what event you are raising .

Regards

Vijay

0 Kudos

Hi,

this class CL_CRM_ALV_GRID is in modul CRM ( OO ALV ).

I write a sugested values to ALV output table, but the the user must decide to save them. I fill the new values in ALV output table a display them, but if I quit the screen with this ALV grid I don't get this SAVE question dialog and these new values are not saved, becouse this ALV don't realized any change from user.

I found that if user make change in cell of ALV output table then the caling of metod "check_changed_data" is realized and I can see the changed item in procces of method "handle_data_changed". But I am not able to raise this event (probably data_changed) manualy and I don't now where to raise this event, at start of PAI main dynpro or only in subscreen ?

Regards

Radek

0 Kudos

Hi Radek,

you need local class to handle it, and set the handler for that events. just check this sample which used cl_gui_alv_grid. i feel both are similar.

and calling the method check_changed_data should be in your PAI.

REPORT  ZTEST1234    MESSAGE-ID ZZ                           .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID,  "First
      G_GRID1 TYPE REF TO CL_GUI_ALV_GRID. "Second
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', "First Container
      G_CONTAINER2 TYPE SCRFNAME VALUE 'TEST1',"Second container
      GS_LAYOUT TYPE LVC_S_LAYO.

DATA:BEGIN OF  ITAB OCCURS 0,
     VBELN LIKE LIKP-VBELN,
     POSNR LIKE LIPS-POSNR,
     LFDAT like lips-vfdat,
     BOX(1),
     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,
<b>**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,</b>**Double Click Handler
    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'.
      SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
      CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

    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
<b>**Handle Data Change
  METHOD HANDLE_DATA_CHANGED.

    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</b>
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
            G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Container2



*- 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.
"First Grid
  CREATE OBJECT G_CUSTOM_CONTAINER
         EXPORTING CONTAINER_NAME = G_CONTAINER1.
  CREATE OBJECT G_GRID
         EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
"Second Grid
  CREATE OBJECT G_CUSTOM_CONTAINER1
         EXPORTING CONTAINER_NAME = G_CONTAINER2.
  CREATE OBJECT G_GRID1
         EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.

* Set a titlebar for the grid control
  CLEAR GS_LAYOUT.
  GS_LAYOUT-GRID_TITLE = TEXT-003.
  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.
  SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
*  SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
 <b> SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.</b>


* 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.
* 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 for First Grid
  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[].
**Calling the Method for ALV output for Second Grid
   CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
*    EXPORTING
*      IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
    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-EDIT      = 'X'.
  X_FIELDCAT-OUTPUTLEN = '10'.

  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 = 'Del Date'(015).
  X_FIELDCAT-FIELDNAME = 'LFDAT'.
  X_FIELDCAT-TABNAME = 'ITAB'.
  X_FIELDCAT-COL_POS    = L_POS.
  X_FIELDCAT-OUTPUTLEN = '10'.
  APPEND X_FIELDCAT TO IT_FIELDCAT.
  CLEAR X_FIELDCAT.
  L_POS = L_POS + 1.
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

Regards

Vijay

0 Kudos

Hi Vijay,

thank You for the example code, it works.

I can handle data_change event, but I need raise this "Handle_data_change" event in program. How can I do this ?

I tried using method raise_event but this is not working.

Regards,

Radek

0 Kudos

hi radek,

you need not to raise it manually, it will be automatically raised.

if you define the local class event handler, and then implement the data_change event and then set the handler

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

refer my code in the above post.

regards

vijay

0 Kudos

Hi,

You can raise the HANDLE_DATA_CHANGED event by calling this method

CALL METHOD LG_ALV_GRID->CHECK_CHANGED_DATA

Where LG_ALV_GRID is a reference variable to CL_GUI_ALV_GRID.

Regards,

Vara

0 Kudos

Hi,

I called this method HANDLE_DATA_CHANGED, but if there in ALV cells no changes, the ALV objets mean there was no changes made - no save. I need set the ALV grid property "GridModified" to value 1. Then then method HANDLE_DATA_CHANGED work like a want. But I can't use method SET_PROPERTY because is protected. I can't override this ALV class in SAP CRM module.

Sorry my english is very bad. I now, this seems very strange what I need. In the CRM standard module in opportunity in strip detail is ALV grid. I must compute the total revenue to every line of ALV grid. e.g. Item revenue in first line must contain 10% of total revenue. I will change this value by changin the content of ALV output (list) table. This works fine - correctly displayed, but then I need that user desides to save this new values - I mustn't change the values in DB. By this way ALV grid don't recognize that there was changes made. I search the way to change cell value like it was by typed from user.

Regards,

Radek

0 Kudos

Hi Radek,

Can you show your Code. may be i can find some thing for you.

Regards

Vijay

0 Kudos

Hi Vijay,

I have I litle bit changed Your code. In menu a defined key F5 with UCOMM 'TEST' to changing the outtable for ALV and raising the event.

Regards

Radek

&----


*& Report ZRD_TEST1 *

*& *

&----


*& *

*& *

&----


REPORT ZRD_TEST1 MESSAGE-ID ZZ .

DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID, "First

G_GRID1 TYPE REF TO CL_GUI_ALV_GRID. "Second

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 'TKONT1', "First Container

G_CONTAINER2 TYPE SCRFNAME VALUE 'TKONT2',"Second container

GS_LAYOUT TYPE LVC_S_LAYO.

DATA:BEGIN OF ITAB OCCURS 0,

partner like BUT000-partner,

name_first like BUT000-name_first,

name_last like BUT000-name_last,

jobgr like BUT000-jobgr,

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

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.

MESSAGE I000 WITH 'Click on job partner number ' V_ROW.

"with this row num you can get the data

IF E_COLUMN = 'partner'.

  • SET PARAMETER ID 'VL' FIELD ITAB-VBELN.

  • CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.

MESSAGE I000 WITH 'Click on job partner number ' E_ROW.

"with this row num you can get the data

ENDIF.

IF E_COLUMN = 'job'.

MESSAGE I000 WITH 'Click on job 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.

MESSAGE I000 WITH 'Handle_data_changed ' V_ROW.

"with this row num you can get the data

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

G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER."Container2

*- 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 partner

name_first

name_last

jobgr

FROM but000

UP TO 500 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.

"First Grid

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER1.

CREATE OBJECT G_GRID

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

"Second Grid

CREATE OBJECT G_CUSTOM_CONTAINER1

EXPORTING CONTAINER_NAME = G_CONTAINER2.

CREATE OBJECT G_GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.

  • Set a titlebar for the grid control

CLEAR GS_LAYOUT.

GS_LAYOUT-GRID_TITLE = TEXT-003.

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.

SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.

  • SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.

SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.

  • 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.

  • 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 for First Grid

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[].

**Calling the Method for ALV output for Second Grid

CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY

  • EXPORTING

  • IT_TOOLBAR_EXCLUDING = LT_EXCLUDE

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 = 'Partner'(024).

X_FIELDCAT-FIELDNAME = 'PARTNER'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-NO_ZERO = 'X'.

X_FIELDCAT-EDIT = 'X'.

X_FIELDCAT-OUTPUTLEN = '10'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SCRTEXT_M = 'Jmeno'(025).

X_FIELDCAT-FIELDNAME = 'NAME_FIRST'.

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 = 'Prijmeni'(015).

X_FIELDCAT-FIELDNAME = 'NAME_LAST'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

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

'TEST'.

  • change partner in 2 row

loop at itab.

if sy-tabix = 2.

itab-partner = 2222222.

modify itab.

endif.

endloop.

        • call method G_GRID-> SET grid modified.

  • call method G_GRID->CHECK_CHANGED_DATA.

  • CALL METHOD g_grid->refresh_table_display.

  • EXPORTING

  • i_soft_refresh = 'X'.

  • CALL METHOD G_GRID->set_ready_for_input

  • EXPORTING

  • i_ready_for_input = 0.

  • call method G_GRID->CHECK_CHANGED_DATA.

WHEN

'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

CALL METHOD G_GRID->CHECK_CHANGED_DATA.

ENDMODULE. " USER_COMMAND_0100 INPUT