我们在定义alv样式的是可以让单元格可编辑
DATA: BEGIN OF WA_FY.
DATA: FYXZTXT TYPE VAL_TEXT," MARK,DEL,
YZFTXT TYPE VAL_TEXT,
SKDW_T TYPE STRING,
FKDW_T TYPE STRING,
******ADD-20190222-BEGIN
VBUND TYPE LFA1-VBUND, "贸易伙伴
SGTXT TYPE SGTXT,
******ADD-20190222-END
JZBZ_T TYPE VAL_TEXT,
SEL,
CELLSTYLES TYPE LVC_T_STYL,
END OF WA_FY.
定义变量:
DATA: l_flag,
lv_canedit(1).
DATA: ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant,"LAYOUT
lt_fcat_fy TYPE lvc_t_fcat,
lt_sort TYPE lvc_t_sort,
ls_sort TYPE lvc_s_sort,
lt_filter TYPE lvc_t_filt,
ls_filter TYPE lvc_s_filt,
ls_celltab TYPE lvc_s_styl,
lt_celltab TYPE lvc_t_styl.
"定义宏,输出grid字段
DEFINE def_grid_fy.
clear g_ls.
g_ls-fieldname = &1.
g_ls-coltext = &2.
g_ls-edit = &3.
if &1 = ‘SEL’.
g_ls-checkbox = ‘X’.
endif.
g_ls-inttype = &5.
-
ENDIF.
g_ls-lzero = ‘X’.
if &1 = ‘SKDW’ or &1 = ‘FKDW’.
g_ls-convexit = ‘ALPHA’.
endif.
g_ls-ref_table = &6.
g_ls-cfieldname = &7.
case &1 .
when ‘BCSQJE’ or ‘UNITPRICE’ or ‘CHGUNIT’
or ‘WAERS1’ or ‘BWBHL’
or ‘CWHL’ or ‘ZSHILV’
or ‘ZSHIE’ or ‘JYPTWXJS’.
g_ls-ref_table = ‘ZMMTUS00730’.
-
G_LS-CFIELDNAME = 'WAERS'.g_ls-ref_field = &1.
endcase.
-
IF &5 = ‘P’.
-
G_LS-DO_SUM = ‘X’.
-
ENDIF.
concatenate &4
‘[]’
into g_table_name. "TABLE BODY
assign (g_table_name) to . "NOT HEADERLINE
append g_ls to .
END-OF-DEFINITION.
调用宏
def_grid_fy ‘CWHL’ text-615 ‘X’ ‘LT_FCAT_FY’ ‘P’ ‘’ ‘’.
def_grid_fy ‘ZSHILV’ text-162 ‘X’ ‘LT_FCAT_FY’ ‘P’ ‘’ ‘’.
类似这样的部分单元格控制是否可编辑
ls_layout-cwidth_opt = ‘X’.
ls_layout-zebra = ‘X’.
*样式表指定控制的内表
ls_layout-stylefname = ‘CELLSTYLES’.
cl_gui_alv_grid的2个不同属性实现不同功能
*控制单元格可编辑
-
ls_celltab-fieldname = 'CWHL'.
-
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
-
INSERT ls_celltab INTO TABLE lt_celltab.
*控制单元格不可编辑
ls_celltab-fieldname = ‘CWHL’.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celltab INTO TABLE lt_celltab.
把指定的样式放到显示的内表字段
CLEAR wa_fy-cellstyles[].
wa_fy-cellstyles[] = lt_celltab[].
MODIFY gt_fy FROM wa_fy.
CREATE OBJECT g_cont_fy
EXPORTING
container_name = ‘CONT_FY’.
CREATE OBJECT g_grid_fy
EXPORTING
i_parent = g_cont_fy
i_appl_events = ‘X’.
CALL METHOD g_grid_fy->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
DATA l_fy_recevier TYPE REF TO lcl_grid_fy_receiver.
CREATE OBJECT l_fy_recevier .
CALL METHOD g_grid_fy->set_table_for_first_display
EXPORTING
is_layout = ls_layout
i_save = ‘A’
is_variant = ls_variant
CHANGING
it_fieldcatalog = lt_fcat_fy
it_outtab = gt_fy
it_sort = lt_sort
it_filter = lt_filter.