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

ALV - Editable

Can i make a field editable at runtime depending on the field value in some other field.

e.g. i have an internal table with fields A and B. and if value of field A is x then B should be editable if it is y then should not be.

Add comment
10|10000 characters needed characters exceeded

3 Answers

  • Posted on Aug 01, 2006 at 03:07 PM

    Hi Amol Dubal ,

    Good

    Check out the following code

    should work fine

    report zk_ex008.

    *

    type-pools: slis.

    TABLES : ZAK_EMPLIST.

    • Data to be displayed

    data: itab_show type table of zak_emplist.

    data: gs_layout type slis_layout_alv.

    ----


    • Selection

    select * from zak_emplist into corresponding fields of table itab_show.

    • Eingabebereit

    gs_layout-edit = 'X'.

    • Call ABAP List Viewer (ALV)

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_callback_program = 'ZK_EX008'

    i_callback_user_command = 'USER_COMMAND'

    i_structure_name = 'ZAK_EMPLIST'

    is_layout = gs_layout

    tables

    t_outtab = ITAB_SHOW.

    form user_command using r_ucomm type sy-ucomm

    rs_selfield type slis_selfield.

    if r_ucomm = '&DATA_SAVE'.

    message i000(0k) with text-001.

    call function 'REUSE_ALV_LIST_DISPLAY'

    exporting

    i_structure_name = 'ZAK_EMPLIST'

    tables

    t_outtab = ITAB_SHOW.

    endif.

    endform.

    check out the following link for more information

    http://www.geocities.com/mpioud/Abap_programs.html

    Good luck and reward me for the same

    Thanks

    Ashok

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 03:11 PM
    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 01, 2006 at 03:32 PM

    Hi ,

    Yes you can do that. Just check this sample code, it will help you a lot.in this code i did it for row 6, but in your case for the rows which you want you have to do the same logic.

    REPORT ZTESTALV.
    
    TYPE-POOLS: SLIS.
    
    *- Fieldcatalog
    DATA: IT_FIELDCAT  TYPE LVC_T_FCAT,
          IT_FIELDCAT1  TYPE SLIS_T_FIELDCAT_ALV..
    *- For Events
    DATA:IT_EVENTS TYPE SLIS_T_EVENT.
    
    DATA:  X_FIELDCAT  TYPE LVC_S_FCAT,
            X_FIELDCAT1  TYPE SLIS_FIELDCAT_ALV.
    DATA:X_LAYOUT TYPE LVC_S_LAYO.
    "{ FOR DISABLE
    DATA: LS_EDIT TYPE LVC_S_STYL,
          LT_EDIT TYPE LVC_T_STYL.
    "} FOR DISABLE
    DATA: BEGIN OF IT_VBAP OCCURS 0,
          VBELN LIKE VBAP-VBELN,
          POSNR LIKE VBAP-POSNR,
          HANDLE_STYLE TYPE LVC_T_STYL, "FOR DISABLE
         END OF IT_VBAP.
    DATA: LS_OUTTAB LIKE LINE OF IT_VBAP.
    SELECT VBELN
           POSNR
           UP TO 10 ROWS
          INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
          FROM VBAP.
    
    
    DATA:L_POS TYPE I VALUE 1.
    CLEAR: L_POS.
    L_POS = L_POS + 1.
    
    X_FIELDCAT-SELTEXT = 'VBELN'.
    X_FIELDCAT-FIELDNAME = 'VBELN'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS    = L_POS.
    X_FIELDCAT-EDIT = 'X'.
    X_FIELDCAT-OUTPUTLEN = '10'.
    x_fieldcat-ref_field = 'VBELN'.
    x_fieldcat-ref_table = 'VBAK'.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    L_POS = L_POS + 1.
    
    X_FIELDCAT-SELTEXT = 'POSNR'.
    X_FIELDCAT-FIELDNAME = 'POSNR'.
    X_FIELDCAT-TABNAME = 'ITAB'.
    X_FIELDCAT-COL_POS    = L_POS.
    X_FIELDCAT-EDIT = 'X'.
    X_FIELDCAT-OUTPUTLEN = '5'.
    APPEND X_FIELDCAT TO IT_FIELDCAT.
    CLEAR X_FIELDCAT.
    L_POS = L_POS + 1.
    <b>"{FOR DISABLE HERE 6ROW IS DISABLED
    SY-TABIX = 6.
    LS_EDIT-FIELDNAME = 'VBELN'.
    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 = 10.
    INSERT LS_EDIT INTO TABLE LT_EDIT.
    LS_EDIT-FIELDNAME = 'POSNR'.
    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 = 6.
    INSERT LS_EDIT INTO TABLE LT_EDIT.
    INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.
    MODIFY IT_VBAP INDEX SY-TABIX FROM LS_OUTTAB  TRANSPORTING
                                      HANDLE_STYLE .
    
    X_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.
    "} UP TO HERE</b>
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        I_CALLBACK_PROGRAM = SY-REPID
        IS_LAYOUT_LVC      = X_LAYOUT
        IT_FIELDCAT_LVC    = IT_FIELDCAT
      TABLES
        T_OUTTAB           = IT_VBAP[]
      EXCEPTIONS
        PROGRAM_ERROR      = 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.

    Regards

    vijay D T T.

    Add comment
    10|10000 characters needed characters exceeded