在ALV报表的选择画面中加一个parameter输入一个布局名称,这样程序运行之前用户可以先选择自己布局。
ALV布局(Layout)的F4函数是 REUSE_ALV_VARIANT_F4。
详细代码如下:
数据定义:
1 2 3 4 5 6 |
DATA: git_fieldcat TYPE lvc_t_fcat, gwa_fieldcat LIKE LINE OF git_fieldcat, git_sort TYPE lvc_t_sort, gwa_variant TYPE disvariant,"layout gwa_sort LIKE LINE OF git_sort, gwa_layout TYPE lvc_s_layo. |
选择画面:
1 2 3 |
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-030. PARAMETERS: p_vari TYPE disvariant-variant. SELECTION-SCREEN END OF BLOCK b2. |
屏幕F4:
布局参数 I_SAVE保存选项:
1:I_SAVE = SPACE. 布局不能被保存
2:I_SAVE = 'U'. 仅自定义的布局可以被保存
3:I_SAVE = 'X'. 仅全局布局可以被保存
4:I_SAVE = 'A'. 自定义的布局和全局的布局都可以被保存
英文如下:
1, ' ' = 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.
2,'X' = Standard save mode
Display variants can be saved as standard display variants.
Saving display variants as user-specific is not possible.
3,'U' = User-specific save mode
Display variants can only be saved as user-specific.
4,'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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari. PERFORM frm_alv_variant_f4. FORM frm_alv_variant_f4. DATA: lwa_variant TYPE disvariant, l_exit TYPE c. lwa_variant-report = sy-repid. lwa_variant-username = sy-uname. CALL FUNCTION 'REUSE_ALV_VARIANT_F4' EXPORTING is_variant = lwa_variant i_save = 'A' IMPORTING e_exit = l_exit es_variant = lwa_variant EXCEPTIONS not_found = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0 OR l_exit = 'X'. EXIT. ENDIF. p_vari = lwa_variant-variant. ENDFORM. |
ALV:alv输入参数is_variant赋值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
gwa_layout-zebra = abap_true. gwa_layout-sel_mode = ''. gwa_layout-cwidth_opt = abap_true. gwa_variant-report = sy-repid. gwa_variant-variant = p_vari. * set catalog PERFORM frm_set_catalog. * set sort PERFORM frm_set_sort. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING is_layout_lvc = gwa_layout it_fieldcat_lvc = git_fieldcat IS_VARIANT = gwa_variant * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = git_alv[] EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. |
显示界面:
以上。
发表评论