Skip to Content
When we have an editable field in ALV , we get stuck when we use ALV GRID Function Module regarding how to make an editable field in display mode  To overcome that we go for Custom containers  Here is a simple solution for that   The below program will make the first 5 fields disabled and the next 7 enabled   REPORT ZALV_DISPLAY_CHANGE.  TABLES :T247.  TYPE-POOLS SLIS.                       “Type definitions for alv report  DATA: IT_FIELDCAT   TYPE   LVC_T_FCAT,       WA_FIELDCAT   TYPE   LVC_S_FCAT.  DATA: WA_LAYOUT     TYPE   LVC_S_LAYO.  DATA : BEGIN OF IT_FINAL OCCURS 0,         CHECK(1),         CELLTAB  TYPE LVC_T_STYL,       ” Switch between display/change         MNR LIKE T247-MNR,         LTX LIKE T247-LTX,        END OF IT_FINAL. DATA : WA_FINAL LIKE IT_FINAL. DATA : W_REPID LIKE SY-REPID.  W_REPID = SY-REPID.  REFRESH IT_FINAL. SELECT MNR LTX        FROM T247        INTO  CORRESPONDING FIELDS OF TABLE IT_FINAL        WHERE SPRAS EQ ‘E’.   WA_FIELDCAT-FIELDNAME = ‘CHECK’. WA_FIELDCAT-TABNAME = ‘IT_FINAL’. WA_FIELDCAT-CHECKBOX = ‘X’. WA_FIELDCAT-EDIT = ‘X’.. WA_FIELDCAT-OUTPUTLEN = ‘3’. WA_FIELDCAT-COL_POS = ‘1’. APPEND WA_FIELDCAT TO IT_FIELDCAT. CLEAR WA_FIELDCAT.  WA_FIELDCAT-FIELDNAME = ‘MNR’. WA_FIELDCAT-TABNAME = ‘IT_FINAL’. WA_FIELDCAT-OUTPUTLEN = ‘8’. WA_FIELDCAT-COL_POS = ‘2’. WA_FIELDCAT-REPTEXT = ‘Month’. APPEND WA_FIELDCAT TO IT_FIELDCAT. CLEAR WA_FIELDCAT.  WA_FIELDCAT-FIELDNAME = ‘LTX’. WA_FIELDCAT-TABNAME = ‘IT_FINAL’. WA_FIELDCAT-OUTPUTLEN = ’20’. WA_FIELDCAT-COL_POS = ‘3’. WA_FIELDCAT-REPTEXT = ‘Month Desc’. APPEND WA_FIELDCAT TO IT_FIELDCAT. CLEAR WA_FIELDCAT.  DATA: WA_CELLTAB TYPE LVC_S_STYL,       IT_CELLTAB TYPE LVC_T_STYL,       L_INDEX    TYPE I. CLEAR : WA_CELLTAB,WA_FINAL,IT_CELLTAB. REFRESH IT_CELLTAB.  *Initialize the celltab table LOOP AT IT_FINAL INTO WA_FINAL.   L_INDEX = SY-TABIX.   WA_CELLTAB-FIELDNAME = ‘CHECK’.   WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.   INSERT WA_CELLTAB INTO TABLE IT_CELLTAB.   INSERT LINES OF IT_CELLTAB INTO TABLE WA_FINAL-CELLTAB.   MODIFY IT_FINAL FROM WA_FINAL INDEX L_INDEX. ENDLOOP.  *Make the first five 5 rows as disabled CLEAR L_INDEX. LOOP AT IT_FINAL INTO WA_FINAL.   L_INDEX = SY-TABIX.   IF SY-TABIX LE 5.     LOOP AT WA_FINAL-CELLTAB INTO WA_CELLTAB.       IF WA_CELLTAB-FIELDNAME EQ ‘CHECK’ .         WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.         MODIFY WA_FINAL-CELLTAB FROM WA_CELLTAB.         MODIFY IT_FINAL  INDEX L_INDEX FROM WA_FINAL TRANSPORTING CELLTAB.       ENDIF.     ENDLOOP.   ENDIF. ENDLOOP.   WA_LAYOUT-BOX_FNAME = ‘CHECK’. WA_LAYOUT-NO_ROWMARK = ‘X’. WA_LAYOUT-STYLEFNAME = ‘CELLTAB’.  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’   EXPORTING     I_CALLBACK_PROGRAM = W_REPID     I_GRID_TITLE       = ‘GRID DISPLAY’     IS_LAYOUT_LVC      = WA_LAYOUT     IT_FIELDCAT_LVC    = IT_FIELDCAT   TABLES     T_OUTTAB           = IT_FINAL   EXCEPTIONS     PROGRAM_ERROR      = 1     OTHERS             = 2.
To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Paul Hardy
    I copied this program into my development system and added a “user command” subroutine so I could see what the state of the internal table was after the “save” button was pressed.
    The cells are editable and you can put ticks in the boxes, but it appears the internal table is not updated i.e. no “X”‘s go into the first column even if you tick the box.
    So it looks like controls are the only way to edit the ALV after all….
    (0) 
    1. Hi Paul,

        Just add this code at the start of your USER_COMMAND subroutine.
      Internal table values will get updated
      Pls let me know any clarifications

      FORM ………

      Data ref1 type ref to cl_gui_alv_grid.
      CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
      IMPORTING
      E_GRID = ref1.
      call method ref1->check_changed_data.

      CASE p_UCOMM.
      ENDCASE.

      ENDFORM.

      (0) 
  2. rajan mehta
    REPORT ZALV_DISPLAY_CHANGE.

    TABLES :T247.

    TYPE-POOLS SLIS. “Type definitions for alv report

    DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
    WA_FIELDCAT TYPE LVC_S_FCAT.
    DATA: GC_CONTAINER_0111    TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
          GC_GRID_0111         TYPE REF TO CL_GUI_ALV_GRID,
          GS_VARIANT           TYPE DISVARIANT,
          G_SAVE               TYPE CHAR01,
          GS_LAYOUT            TYPE LVC_S_LAYO.

    DATA: WA_LAYOUT TYPE LVC_S_LAYO.
    TYPES : BEGIN OF TY_FINAL ,
            CHECK(1),
            CELLTAB TYPE LVC_T_STYL, ” Switch between display/change
            MNR LIKE T247-MNR,
            LTX LIKE T247-LTX,
    END OF TY_FINAL.
    DATA :  C_USER_CMD TYPE SLIS_FORMNAME VALUE ‘USER_COMMAND’.
    DATA : BEGIN OF IT_FINAL OCCURS 0,
    CHECK_R(1)  ,
    CHECK(1),
    CELLTAB TYPE LVC_T_STYL, ” Switch between display/change
    MNR LIKE T247-MNR,
    LTX LIKE T247-LTX,
    END OF IT_FINAL.
    DATA : WA_FINAL LIKE IT_FINAL.
    DATA : W_REPID LIKE SY-REPID.

    W_REPID = SY-REPID.

    REFRESH IT_FINAL.
    SELECT MNR LTX
    FROM T247
    INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
    WHERE SPRAS EQ ‘E’.

    *WA_FIELDCAT-FIELDNAME = ‘CHECK_R’.
    *WA_FIELDCAT-TABNAME = ‘IT_FINAL’.
    *WA_FIELDCAT-CHECKBOX = ‘X’.
    *WA_FIELDCAT-EDIT = ‘X’..
    *WA_FIELDCAT-OUTPUTLEN = ‘3’.
    *WA_FIELDCAT-COL_POS = ‘1’.
    *APPEND WA_FIELDCAT TO IT_FIELDCAT.
    *CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = ‘CHECK’.
    WA_FIELDCAT-TABNAME = ‘IT_FINAL’.
    WA_FIELDCAT-CHECKBOX = ‘X’.
    WA_FIELDCAT-EDIT = ‘X’..
    WA_FIELDCAT-OUTPUTLEN = ‘3’.
    WA_FIELDCAT-COL_POS = ‘1’.
    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = ‘MNR’.
    WA_FIELDCAT-TABNAME = ‘IT_FINAL’.
    WA_FIELDCAT-OUTPUTLEN = ‘8’.
    WA_FIELDCAT-COL_POS = ‘2’.
    WA_FIELDCAT-REPTEXT = ‘Month’.
    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = ‘LTX’.
    WA_FIELDCAT-TABNAME = ‘IT_FINAL’.
    WA_FIELDCAT-OUTPUTLEN = ’20’.
    WA_FIELDCAT-COL_POS = ‘3’.
    WA_FIELDCAT-REPTEXT = ‘Month Desc’.
    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    DATA: WA_CELLTAB TYPE LVC_S_STYL,
    IT_CELLTAB TYPE LVC_T_STYL,
    L_INDEX TYPE I.
    CLEAR : WA_CELLTAB,WA_FINAL,IT_CELLTAB.
    REFRESH IT_CELLTAB.

    *Initialize the celltab table
    LOOP AT IT_FINAL INTO WA_FINAL.
      L_INDEX = SY-TABIX.
      WA_CELLTAB-FIELDNAME = ‘CHECK’.
    *  WA_FINAL-CHECK =  ‘X’.
      WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
      INSERT WA_CELLTAB INTO TABLE IT_CELLTAB.
      INSERT LINES OF IT_CELLTAB INTO TABLE WA_FINAL-CELLTAB.
      MODIFY IT_FINAL FROM WA_FINAL INDEX L_INDEX.
    ENDLOOP.

    *Make the first five 5 rows as disabled
    CLEAR L_INDEX.
    LOOP AT IT_FINAL INTO WA_FINAL.
      L_INDEX = SY-TABIX.
      IF SY-TABIX LE 5.
        LOOP AT WA_FINAL-CELLTAB INTO WA_CELLTAB.
          IF WA_CELLTAB-FIELDNAME EQ ‘CHECK’ .
            WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
            MODIFY WA_FINAL-CELLTAB FROM WA_CELLTAB.
            MODIFY IT_FINAL INDEX L_INDEX FROM WA_FINAL TRANSPORTING CELLTAB.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDLOOP.

    WA_LAYOUT-SEL_MODE = ‘A’.
    WA_LAYOUT-BOX_FNAME = ‘CHECK’.
    WA_LAYOUT-NO_ROWMARK = ‘X’.
    WA_LAYOUT-STYLEFNAME = ‘CELLTAB’.

    CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
      EXPORTING
        I_CALLBACK_PROGRAM      = W_REPID
        I_GRID_TITLE            = ‘GRID DISPLAY’
        IS_LAYOUT_LVC           = WA_LAYOUT
        I_CALLBACK_USER_COMMAND = C_USER_CMD
        IT_FIELDCAT_LVC         = IT_FIELDCAT
      TABLES
        T_OUTTAB                = IT_FINAL
      EXCEPTIONS
        PROGRAM_ERROR           = 1
        OTHERS                  = 2.

    WRITE ‘RAJAN’ .

    *&———————————————————————*
    *&      Form  USER_COMMAND
    *&———————————————————————*
    *       text
    *———————————————————————-*
    FORM USER_COMMAND USING RUCOMM TYPE SY-UCOMM
                            SELECT_FIELD TYPE SLIS_SELFIELD.

      DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.

      IF RUCOMM = ‘&DATA_SAVE’.

        CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
          IMPORTING
            E_GRID = REF1.
       
        CALL METHOD REF1->CHECK_CHANGED_DATA.

      ENDIF.

    ENDFORM.                    “USER_COMMAND

    This is my code

    when i mark any field it is not getting updated even if i have used check_change_data

    pls help me on this

    By the way the blog is really helpfull but help me out why it is not getting updated

    i have pasted my code abobe

    u rocks ….

    Regards
    rajan

    (0) 
  3. João Gaia
    Hi,

    I would like to know if it works with fm “REUSE_ALV_GRID_DISPLAY”?

    I have a request to create a new column in an program already done, but the column will be editable only if the value is greater 0.

    I tried to change the program according your code, but without success. The is_layout are diferent for fms “REUSE_ALV_GRID_DISPLAY” and ‘REUSE_ALV_GRID_DISPLAY_LVC’.

    I would appreciate any help.

    Thanks in advance.
    Joao Gaia

    (0) 

Leave a Reply