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: 

ALV grid Editable based on a Field value

Former Member
0 Kudos
5,930

Hi,

I need to make a ALV Grid Row editable based on a particular field of that row.

For example

if fields are A B C D

and if there are three rows of data

I must make the Field B editable in all the rows which have D value as X else it must be non Editable.

I searched in SDN but could not find a suitable answer.

Hope I am clear with my issue.

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos
485

this sample code makes the NETPR field editable based on a desired condition.

this is the solution to your problem.

* TABLES:     ekko.
* TYPE-POOLS: slis.
* TYPES: BEGIN OF t_ekko,
*  ebeln TYPE ekpo-ebeln,
*  ebelp TYPE ekpo-ebelp,
*  netpr TYPE ekpo-netpr,
*  field_style  TYPE lvc_t_styl, 
* END OF t_ekko.

*DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
*      wa_ekko TYPE t_ekko.

*DATA: it_fieldcat TYPE lvc_t_fcat,     
*      wa_fieldcat TYPE lvc_s_fcat,
*
*      gd_tab_group TYPE slis_t_sp_group_alv,
*      gd_layout    TYPE lvc_s_layo,   
*      gd_repid     LIKE sy-repid.

*START-OF-SELECTION.
*SELECT ebeln ebelp netpr 
*   UP TO 10 ROWS
*    FROM ekpo
*    INTO  CORRESPONDING FIELDS OF TABLE it_ekko.

*  DATA ls_stylerow TYPE lvc_s_styl .
*  DATA lt_styletab TYPE lvc_t_styl .

** The following code sets it to be disabled(display only) if 'NETPR'
** is gt than 10.
*
*  LOOP AT it_ekko INTO wa_ekko.
*    IF wa_ekko-netpr GT 10.
*      ls_stylerow-fieldname = 'NETPR' .
*      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
*      APPEND ls_stylerow  TO wa_ekko-field_style.
*      MODIFY it_ekko FROM wa_ekko.
*    ENDIF.
*  ENDLOOP.

*  wa_fieldcat-fieldname   = 'EBELN'.
*  wa_fieldcat-scrtext_m   = 'Purchase Order'.
*  wa_fieldcat-col_pos     = 1.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.
*
*  wa_fieldcat-fieldname   = 'EBELP'.
*  wa_fieldcat-scrtext_m   = 'PO Item'.
*  wa_fieldcat-col_pos     = 2.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.
*
*  wa_fieldcat-fieldname   = 'NETPR'.
*  wa_fieldcat-scrtext_m   = 'Net Price'.
*  wa_fieldcat-edit        = 'X'. "sets whole column to be editable
*  wa_fieldcat-col_pos     = 3.
*  wa_fieldcat-datatype     = 'CURR'.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.

*  gd_layout-stylefname = 'FIELD_STYLE'.
*  gd_layout-zebra             = 'X'.

*  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
*       EXPORTING
*            i_callback_program       = sy-repid
*            is_layout_lvc            = gd_layout
*            it_fieldcat_lvc          = it_fieldcat
*            i_save                   = 'X'
*       TABLES
*            t_outtab                = it_ekko

8 REPLIES 8

Former Member
0 Kudos
485

HI,

Please help.

Am I clear with my question

Former Member
0 Kudos
485

hi,

While giving the field catalog for each field, you give edit option

for eg: w_field-tabname = 'itab'.

w_field-edit = 'X'.

append w_field to i_field.

regards,

Manesh.R

0 Kudos
485

Hi,

That will Statically set the fieldcat and All the rows will be editable.

I want only a few rows to be editable based on the my condition.

Regards

anversha_s
Active Contributor
0 Kudos
485

hi,

You have to use littile bit object oreiented technique for this requirement.

1. use the FM '

REUSE_ALV_GRID_DISPLAY_LVC

' for displaying grid.

Pls find a sample code.

DATA: ref_grid TYPE REF TO cl_gui_alv_grid.
DATA:ls_stylerow TYPE lvc_s_styl,
     v_mbrsh TYPE mbrsh.

IF ref_grid IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ref_grid.
ENDIF.

LOOP AT gt_outtab INTO wa_outtab.
IF wa_outtab-D NE 'D'.
ls_stylerow-fieldname = 'C'.
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
APPEND ls_stylerow TO wa_outtab-celltab.
MODIFY gt_outtab FROM wa_outtab.
ENDIF.
CLEAR : wa_outtab,ls_stylerow.
ENDLOOP.

Regards,

Anversha

0 Kudos
485

HI Anversha ,

Thanks for the reply.

Could you give me a more clear ans please.

Regards

0 Kudos
485

Hi,

What Anversha said is correct, but liitle change to it.

Try like below,


"Additional declarations
      TYPES: BEGIN OF g_ty_itab,
             a TYPE string,
             b TYPE string,
             c TYPE string,
             d TYPE c,
             celltab TYPE lvc_t_styl,  " Extra field in internal table for making particular field ready for input
             END OF g_ty_itab.

      DATA: g_t_itab TYPE STANDARD TABLE OF g_ty_itab,
            g_r_itab TYPE g_ty_itab,
            l_celltab TYPE lvc_s_styl,
            l_t_celltab TYPE lvc_t_styl.

"After filling internal table with values add below code.
      LOOP AT g_t_itab INTO g_r_itab.
        IF g_r_itab-d = 'X'.   " When field D is 'X'
          l_celltab-fieldname = 'B'.
          l_celltab-style = cl_gui_alv_grid=>mc_style_enabled. " Make field B editable
          APPEND l_celltab TO l_t_celltab.
          INSERT lines of l_t_celltab INTO TABLE g_r_itab-celltab.
          MODIFY g_t_itab FROM g_r_itab TRANSPORTING celltab.
          CLEAR: l_t_celltab, g_r_itab.
        ENDIF.
      ENDLOOP.

Thanks,

Former Member
0 Kudos
486

this sample code makes the NETPR field editable based on a desired condition.

this is the solution to your problem.

* TABLES:     ekko.
* TYPE-POOLS: slis.
* TYPES: BEGIN OF t_ekko,
*  ebeln TYPE ekpo-ebeln,
*  ebelp TYPE ekpo-ebelp,
*  netpr TYPE ekpo-netpr,
*  field_style  TYPE lvc_t_styl, 
* END OF t_ekko.

*DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
*      wa_ekko TYPE t_ekko.

*DATA: it_fieldcat TYPE lvc_t_fcat,     
*      wa_fieldcat TYPE lvc_s_fcat,
*
*      gd_tab_group TYPE slis_t_sp_group_alv,
*      gd_layout    TYPE lvc_s_layo,   
*      gd_repid     LIKE sy-repid.

*START-OF-SELECTION.
*SELECT ebeln ebelp netpr 
*   UP TO 10 ROWS
*    FROM ekpo
*    INTO  CORRESPONDING FIELDS OF TABLE it_ekko.

*  DATA ls_stylerow TYPE lvc_s_styl .
*  DATA lt_styletab TYPE lvc_t_styl .

** The following code sets it to be disabled(display only) if 'NETPR'
** is gt than 10.
*
*  LOOP AT it_ekko INTO wa_ekko.
*    IF wa_ekko-netpr GT 10.
*      ls_stylerow-fieldname = 'NETPR' .
*      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
*      APPEND ls_stylerow  TO wa_ekko-field_style.
*      MODIFY it_ekko FROM wa_ekko.
*    ENDIF.
*  ENDLOOP.

*  wa_fieldcat-fieldname   = 'EBELN'.
*  wa_fieldcat-scrtext_m   = 'Purchase Order'.
*  wa_fieldcat-col_pos     = 1.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.
*
*  wa_fieldcat-fieldname   = 'EBELP'.
*  wa_fieldcat-scrtext_m   = 'PO Item'.
*  wa_fieldcat-col_pos     = 2.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.
*
*  wa_fieldcat-fieldname   = 'NETPR'.
*  wa_fieldcat-scrtext_m   = 'Net Price'.
*  wa_fieldcat-edit        = 'X'. "sets whole column to be editable
*  wa_fieldcat-col_pos     = 3.
*  wa_fieldcat-datatype     = 'CURR'.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR  wa_fieldcat.

*  gd_layout-stylefname = 'FIELD_STYLE'.
*  gd_layout-zebra             = 'X'.

*  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
*       EXPORTING
*            i_callback_program       = sy-repid
*            is_layout_lvc            = gd_layout
*            it_fieldcat_lvc          = it_fieldcat
*            i_save                   = 'X'
*       TABLES
*            t_outtab                = it_ekko

Former Member
0 Kudos
485

BCALV_TEST_GRID_EDITABLE