Archived discussions are read-only. Learn more about SAP Q&A

ALV + layout varient on selection screen

hiii

with ALV list i want to know with how to allow to put the layout on the selection screen and when user press F4 he will be able to use the list of layout he has save on the ALV output

Note for the layout button to appear i had to activate shown below:

i_save = c_x

please give me sample code where user can choose layout on selection screen and this layout will be used to display on ALV

Tags:
replied

Hi,

Please refer the code below for layout variants :

DATA:   gt_rsparams  TYPE TABLE OF rsparams.

* Data for ALV variant
DATA  gv_repname          LIKE sy-repid.
DATA  gv_x_variant        LIKE disvariant.
DATA  gv_exit(1)          TYPE c.
DATA  gv_save(1)          TYPE c.
DATA  gv_variant          LIKE disvariant.

PARAMETERS: sp_vari LIKE disvariant-variant.        "Dispaly Variant


INITIALIZATION.

  gv_repname = sy-repid.
  REFRESH : gt_glacct,
            gr_rcomp,
            gt_output,
            gt_fieldcat,
            gt_sort.

* Initialize ALV Layout variant
  PERFORM f_initialize_variant.


FORM f_initialize_variant .

  CLEAR gv_variant.
  gv_save           = 'X'.
  gv_variant-report = gv_repname.
  gv_x_variant      = gv_variant.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = gv_save
    CHANGING
      cs_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 0.

    sp_vari = gv_x_variant-variant.

  ENDIF.

ENDFORM.                    " f_initialize_variant


AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_vari.
  PERFORM f_f4_for_variant.

FORM f_f4_for_variant .
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = gv_variant
      i_save     = gv_save
    IMPORTING
      e_exit     = gv_exit
      es_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 2.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF gv_exit = space.
      sp_vari = gv_x_variant-variant.
    ENDIF.
  ENDIF.

ENDFORM.                    " f_f4_for_variant

AT SELECTION-SCREEN.

*  Validating selection screen fields
  PERFORM f_at_selection_screen.

FORM f_at_selection_screen .

* ALV Layout variant
  IF NOT sp_vari IS INITIAL.

    MOVE gv_variant TO gv_x_variant.
    MOVE sp_vari    TO gv_x_variant-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
      EXPORTING
        i_save     = gv_save
      CHANGING
        cs_variant = gv_x_variant.
    gv_variant = gv_x_variant.

  ELSE.

    PERFORM f_initialize_variant.

  ENDIF.

FORM f_initialize_variant .

  CLEAR gv_variant.
  gv_save           = 'X'.
  gv_variant-report = gv_repname.
  gv_x_variant      = gv_variant.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = gv_save
    CHANGING
      cs_variant = gv_x_variant
    EXCEPTIONS
      not_found  = 2.

  IF sy-subrc = 0.

    sp_vari = gv_x_variant-variant.

  ENDIF.

ENDFORM.                    " f_initialize_variant

Thanks,

Sriram POnna.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question