Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Select Variant (ALV Layout) from selection screen (REUSE_ALV_GRID_DISPLAY)

Former Member
0 Kudos
383

Hi,

In my current program, I have to allow the user to select their ALV Layout variant from the initial selection screen (via a button and pop-up.)

The ALV is called using FM 'REUSE_ALV_GRID_DISPLAY.'

Help will be very appreciated and rewarded.

Thanks,

John

6 REPLIES 6

Former Member
0 Kudos
85

Declerations you need to make

data: WK_VARIANT LIKE DISVARIANT,

WX_VARIANT LIKE DISVARIANT,

WK_REPID LIKE SY-REPID,

WK_VARIANT_SAVE(1) TYPE C,

WK_EXIT(1) TYPE C.

Things you need to do in the initialization event:

INITIALIZATION.

PERFORM F_INIT_VARIANT.

PERFORM F_VARIANT_DEFAULT USING PR_VARI.

&----


*& Form f_init_variant

&----


FORM F_INIT_VARIANT .

CLEAR WK_VARIANT.

WK_REPID = SY-REPID.

WK_VARIANT-REPORT = WK_REPID.

WK_VARIANT-USERNAME = SY-UNAME.

WK_VARIANT_SAVE = 'A'.

ENDFORM. " f_init_variant

&----


*& Form f_variant_default

&----


FORM F_VARIANT_DEFAULT USING P_PR_VARI.

WX_VARIANT = WK_VARIANT.

IF NOT P_PR_VARI IS INITIAL.

WX_VARIANT-VARIANT = P_PR_VARI.

ENDIF.

CALL FUNCTION 'LVC_VARIANT_DEFAULT_GET'

EXPORTING

I_SAVE = WK_VARIANT_SAVE

CHANGING

CS_VARIANT = WX_VARIANT

EXCEPTIONS

WRONG_INPUT = 1

NOT_FOUND = 2

PROGRAM_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CASE SY-SUBRC.

WHEN 0.

P_PR_VARI = WX_VARIANT-VARIANT.

WHEN 2.

CLEAR P_PR_VARI.

ENDCASE.

ENDFORM. " f_variant_default

After this Things you need to do in the At selection screen event:

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_VARI.

PERFORM F_VARIANT_F4 USING PR_VARI.

&----


*& Form f_variant_f4

&----


FORM F_VARIANT_F4 USING P_PR_VARI.

CALL FUNCTION 'LVC_VARIANT_F4'

EXPORTING

IS_VARIANT = WK_VARIANT

I_SAVE = WK_VARIANT_SAVE

IMPORTING

E_EXIT = WK_EXIT

ES_VARIANT = WX_VARIANT

EXCEPTIONS

NOT_FOUND = 1

PROGRAM_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF WK_EXIT IS INITIAL.

WK_VARIANT-VARIANT = WX_VARIANT-VARIANT.

P_PR_VARI = WX_VARIANT-VARIANT.

ENDIF.

ENDFORM. " f_variant_f4

After this finally when you call the output using REUSE_ALV_GRID_DISPLAY YOU NEED TO mention this parameter in the function module

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IS_LAYOUT = WA_LAYOUT

I_SAVE = 'X'

I_DEFAULT = 'X'

IS_VARIANT = WK_VARIANT

TABLES

T_OUTTAB = ITAB1

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

Once you do this,,, you can create a layout variant.

0 Kudos
85

How is the variant selected (button is preferred; paramater?)

0 Kudos
85

parameter

0 Kudos
85

Is it possible for the user to select the variant by using a button?

0 Kudos
85

hi ,

am not sure,try to put this logic with the button ..

Thanks

Mahesh

uwe_schieferstein
Active Contributor
0 Kudos
85

Hello John

Although it is unusual to select the ALV layout via button the following sample report <b>ZUS_SDN_REUSE_ALV_GRID_DISPLAY</b> shows two ways to realise your requirement:

- choose via F4 help

- choose via button

Regards

Uwe