避免不同的同一个 ALV 显示不同数据时,layout variant 混淆
DATA: ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
IF ... .
ls_variant-handle = 'YS'.
ELSE.
ls_variant-handle = ''.
ENDIF.
DATA: ls_style TYPE lvc_s_styl.
DEFINE _set_editable.
read table &1-celstyle with table key fieldname = &2 into ls_style.
if sy-subrc eq 0.
ls_style-style = ls_style-style bit-or cl_gui_alv_grid=>mc_style_enabled.
modify table &1-celstyle from ls_style.
else.
clear ls_style.
ls_style-fieldname = &2.
ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
insert ls_style into table &1-celstyle.
endif.
END-OF-DEFINITION.
DEFINE _set_readonly.
read table &1-celstyle with table key fieldname = &2 into ls_style.
if sy-subrc eq 0.
ls_style-style = ls_style-style bit-and bit-not cl_gui_alv_grid=>mc_style_enabled.
modify table &1-celstyle from ls_style.
else.
END-OF-DEFINITION.
DEFINE _set_deletable.
read table &1-celstyle with table key fieldname = space into ls_style.
if sy-subrc eq 0.
ls_style-style = ls_style-style bit-and bit-not cl_gui_alv_grid=>mc_style_no_delete_row.
modify table &1-celstyle from ls_style.
else.
END-OF-DEFINITION.
DEFINE _set_cellcolor.
&1-fname = &3.
&1-color-col = substring( val = &2 off = 0 len = 1 ).
&1-color-int = substring( val = &2 off = 1 len = 1 ).
&1-color-inv = substring( val = &2 off = 2 len = 1 ).
append &1 to <line001>-celcolor.
END-OF-DEFINITION.
DEFINE _set_undeletable.
read table &1-celstyle with table key fieldname = &2 into ls_style.
if sy-subrc eq 0.
ls_style-style = ls_style-style bit-or cl_gui_alv_grid=>mc_style_no_delete_row.
modify table &1-celstyle from ls_style.
else.
clear ls_style.
ls_style-fieldname = &2.
ls_style-style = cl_gui_alv_grid=>mc_style_no_delete_row.
insert ls_style into table &1-celstyle.
endif.
END-OF-DEFINITION.
DEFINE _set_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = &1.
ls_fieldcat-coltext = &2.
ls_fieldcat-seltext = &2.
* ls_fieldcat-rollname = &3.
ls_fieldcat-fix_column = &3.
ls_fieldcat-outputlen = &4. " 输入长度,即按长度,否则优化列宽
ls_fieldcat-col_opt = boolc( concat( &4 ) = space ).
ls_fieldcat-no_out = boolc( concat( &4 ) = '0' ).
ls_fieldcat-checkbox = &5.
ls_fieldcat-f4availabl = &6.
ls_fieldcat-ref_field = &7.
ls_fieldcat-ref_table = &8.
* ls_fieldcat-emphasize = &9.
if &9 is not initial.
ls_fieldcat-edit_mask = '==' && &9.
ls_fieldcat-convexit = &9.
endif.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.