BMW3000
BMW3000

Reputation: 111

How to display itab in ALV with dynamic layout variant?

I am using the class CL_GUI_ALV_GRID and a dynpro screen to display an internal table via the ALV tool.

In my selection screen I have a dropdown list where the user can choose a layout variant for the displayed internal table. The layout variants are stored in the table LTDX.

Now, back to my question, how can I display the variants depending on the selection of the user?

Upvotes: 0

Views: 6901

Answers (1)

futu
futu

Reputation: 897

You supply in the initial set_table_for_first_display method the is_variant parameter:

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
        ...

EDIT: okay you did not accept the simple answer, so I will add the manual alternative:

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.

Upvotes: 4

Related Questions