*&---------------------------------------------------------------------*
*& 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.
ALV设置单元格可编辑性
最新推荐文章于 2025-05-30 14:23:32 发布