ALV设置单元格可编辑性

 *&---------------------------------------------------------------------*
*& Report  Z01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z01.
data: gt_fieldcat type table of LVC_S_FCAT with header line,
      gs_layout type LVC_S_LAYO.
data g_repid like sy-repid.
data field_style type LVC_S_STYL.

types: begin of wa,
  col1 type i,
  col2 type i,
  field_style TYPE LVC_T_STYL,      "设置单元格为不可编辑的内表
end of wa.
data gt_itab type standard table of wa with header line.

do 6 times.
  gt_itab-col1 = sy-index.
  gt_itab-col2 = sy-index ** 2.
  append gt_itab.
enddo.

gt_fieldcat-col_pos = 1.
gt_fieldcat-fieldname = 'COL1'.
gt_fieldcat-seltext = '一列'.
gt_fieldcat-do_sum = 'X'.
gt_fieldcat-edit = 'X'.      "设置该列为可编辑
append gt_fieldcat.
clear gt_fieldcat.

gt_fieldcat-col_pos = 2.
gt_fieldcat-fieldname = 'COL2'.
gt_fieldcat-seltext = 'col2'.
append gt_fieldcat.
clear gt_fieldcat.

loop at gt_itab.
  if gt_itab-col1 = 2 or gt_itab-col1 = 4.
    field_style-fieldname = 'COL1'.
    field_style-style = cl_gui_alv_grid=>mc_style_disabled.     "对某些不需要可编辑的单元格,调用方法设置为不可编辑
    append field_style to gt_itab-field_style.
    clear field_style.
    modify gt_itab transporting field_style.
  endif.
endloop.

gs_layout-stylefname = 'FIELD_STYLE'.
gs_layout-zebra = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
  I_CALLBACK_PROGRAM = g_repid
  IS_LAYOUT_LVC                      = gs_layout
   IT_FIELDCAT_LVC                           = gt_fieldcat[]
  TABLES
    T_OUTTAB                          = gt_itab[]
 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值