2007 Aug 17 8:42 PM
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
2007 Aug 17 8:47 PM
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.
2007 Aug 17 8:50 PM
2007 Aug 17 8:51 PM
2007 Aug 17 8:53 PM
Is it possible for the user to select the variant by using a button?
2007 Aug 17 8:56 PM
hi ,
am not sure,try to put this logic with the button ..
Thanks
Mahesh
2007 Aug 17 9:20 PM
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