如何在具有动态布局变体的ALV中显示itab?

时间:2019-02-11 10:06:34

标签: sap abap alv

我正在使用类CL_GUI_ALV_GRID和dynpro屏幕通过ALV工具显示内部表。

在我的选择屏幕中,我有一个下拉列表,用户可以在其中选择所显示内部表的布局变式。布局变体存储在表LTDX中。

现在,回到我的问题,如何根据用户的选择显示变体?

1 个答案:

答案 0 :(得分:4)

您使用初始set_table_for_first_display方法提供了is_variant参数:

DATA: ls_variant TYPE disvariant.


CLEAR: ls_variant.
ls_variant-report   = sy-repid.
ls_variant-variant  = pa_varid. "<<< this is the name of the variant

CALL METHOD gro_alv100->set_table_for_first_display
      EXPORTING
        is_variant                    = ls_variant
        ...

编辑:好的,您不接受简单的答案,因此我将添加手动替代方法:

FORM set_variant USING ps_variant TYPE disvariant.

  DATA: lf_user_specific TYPE char1,
        ls_stable  TYPE lvc_s_stbl VALUE 'XX'.

  CHECK ps_variant-variant IS NOT INITIAL.

  lf_user_specific = boolc( ps_variant-variant(1) <> '/' ).
  CALL FUNCTION 'LVC_VARIANT_SELECT'
    EXPORTING
      i_dialog            = space
      i_user_specific     = lf_user_specific
      i_default           = space
      it_default_fieldcat = gt_fcat
    IMPORTING
      et_fieldcat         = gt_fcat
      et_sort             = gt_sort
      et_filter           = gt_filter 
    TABLES
      it_data             = gt_outtab
    CHANGING
      cs_variant          = ps_variant
    EXCEPTIONS
      wrong_input         = 1
      fc_not_complete     = 2
      not_found           = 3
      program_error       = 4
      data_missing        = 5
      OTHERS              = 6.
  IF sy-subrc <> 0.
  ENDIF.

  gro_alv100->set_variant( EXPORTING is_variant = ps_variant ).
  gro_alv100->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = gt_fcat ).
  gro_alv100->set_sort_criteria( EXPORTING it_sort = gt_sort ).
  gro_alv100->set_filter_criteria( EXPORTING it_filter = gt_filter ).

  gro_alv100->refresh_table_display( EXPORTING is_stable = ls_stable i_soft_refresh = abap_false ).
ENDFORM.