问题
今天有user反映希望程序alv结果可以保存layout,但save layout按钮为灰色。程序实现alv方法为CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’。
原因
经debug发现’REUSE_ALV_GRID_DISPLAY’中参数i_save值为空值space。
i_save参数官方介绍如下:
’ ’ = Display variants cannot be saved (不能保存)
Defined display variants (such as delivered display variants) can be selected for presentation regardless of this indicator. However, changes cannot be saved.
’X’ = Standard save mode (全局布局可以保存)
Display variants can be saved as standard display variants.
Saving display variants as user-specific is not possible.
’U’ = User-specific save mode (用户自定义布局可以保存)
Display variants can only be saved as user-specific.
’A’ = Standard and user-specific save mode (全局和用户自定义布局都可以保存)
Display variants can be saved both as user-specific and as standard
variants. Users make their choice on the dialog box for saving the
display variant.
解决办法
将i_save值写死赋值为A,测试后发现可以保存layout,选择屏幕layout输入框需要做F4帮助,方便user直接选择自己layout并保存variant。
以下为与layout相关部分代码,wk_vari为选择屏幕上layout输入框。
DATA : variante LIKE disvariant,
def_variante LIKE disvariant,
variant_exit(1) TYPE c,
variant_save(1) TYPE c.
PARAMETERS: wk_vari LIKE disvariant-variant.
INITIALIZATION.
variant_save = 'A'.
CLEAR variante.
variante-report = sy-repid.
def_variante = variante.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = variant_save
CHANGING
cs_variant = def_variante
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.
IF sy-subrc = 0.
wk_vari = def_variante-variant.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR wk_vari.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = variante
i_save = variant_save
IMPORTING
e_exit = variant_exit
es_variant = def_variante
EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 2.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF variant_exit = space.
wk_vari = def_variante-variant.
ENDIF.
ENDIF.
AT SELECTION-SCREEN.
IF NOT wk_vari IS INITIAL.
MOVE variante TO def_variante.
MOVE wk_vari TO def_variante-variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = variant_save
CHANGING
cs_variant = def_variante.
variante = def_variante.
ELSE.
CLEAR variante.
variante-report = sy-repid.
ENDIF.
"调用alv函数时赋值i_save、is_variant参数即可
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_interface_check = ''
i_callback_program = sy-repid
it_fieldcat = xfieldcat[]
i_default = 'X'
i_save = variant_save
is_layout = layout
is_variant = variante
TABLES
t_outtab = inttab
EXCEPTIONS
program_error = 1
OTHERS = 2.