Skip to Content
author's profile photo Former Member
Former Member

ABAP code for creating a report variant

Hi,

I would like to create parameter on selection screen type SLIS_VARI. I would like that the program will start with pre-defined variant in ALV grid, the same as it is on standard stock report (MB52)...

Can someone tell me how to do this, and where to put the code?

Thanks in advance,

Saso

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 08:55 AM

    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.

    PARAMETERS: p_var TYPE variant DEFAULT '/GENERAL',

    p_dvar TYPE variant DEFAULT '/DOWNLOAD'.

    SELECTION-SCREEN END OF BLOCK b2.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dvar.

    PERFORM f_get_f4_variants USING gc_a

    text-086

    CHANGING p_var.

    FORM f_get_f4_variants USING rc_a TYPE gty_char01

    rv_text TYPE any

    CHANGING rv_var TYPE variant.

    DATA: ls_layout_variant TYPE disvariant.

    ls_layout_variant = sy-repid.

    CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

    EXPORTING

    is_variant = ls_layout_variant

    i_save = rc_a

    IMPORTING

    es_variant = ls_layout_variant

    EXCEPTIONS

    not_found = 1

    program_error = 2

    OTHERS = 3.

    IF sy-subrc EQ 2.

    MESSAGE i000 WITH rv_text.

    ELSE.

    rv_var = ls_layout_variant-variant.

    ENDIF.

    ENDFORM. " F_GET_F4_VARIANTS

    *& Validating alv variants

    AT SELECTION-SCREEN ON p_var.

    PERFORM f_check_variants_exist USING p_var

    text-086.

    FORM f_check_variants_exist USING rv_var TYPE variant

    rv_text TYPE any.

    DATA ls_variant type disvariant.

    IF NOT rv_var IS INITIAL.

    MOVE: sy-repid TO ls_variant-report,

    rv_var TO ls_variant-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

    EXPORTING

    i_save = 'A'

    CHANGING

    cs_variant = ls_variant

    EXCEPTIONS

    wrong_input = 1

    not_found = 2

    program_error = 3

    OTHERS = 4.

    IF sy-subrc NE 0.

    MESSAGE e000 WITH rv_text.

    ENDIF.

    ENDIF.

    ENDFORM. " f_check_variants_exist

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 08:57 AM

    Hi,

    This is the code for variant as parameter and F4 help.

    DATA: g_repid LIKE sy-repid,

    g_dynnr LIKE sy-dynnr.

    DATA: g_save(1) TYPE c VALUE 'A',

    g_exit(1) TYPE c,

    gx_variant LIKE disvariant,

    g_variant LIKE disvariant.

    PARAMETERS: p_vari LIKE disvariant-variant.

    INITIALIZATION.

    g_repid = sy-repid.

    g_dynnr = sy-dynnr.

    PERFORM variant_init.

    *Get default variant

    gx_variant = g_variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

    EXPORTING

    i_save = g_save

    CHANGING

    cs_variant = gx_variant

    EXCEPTIONS

    not_found = 2.

    IF sy-subrc = 0.

    p_vari = gx_variant-variant.

    ENDIF.

    ----


    • AT SELECTION SCREEN *

    ----


    AT SELECTION-SCREEN.

    *--PAI of selection screen

    PERFORM pai_of_selection_screen.

    *---F4 option for report variant

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

    PERFORM f4_for_variant.

    ----


    • SUB-ROUTINES *

    ----


    FORM variant_init.

    CLEAR g_variant.

    g_variant-report = g_repid.

    ENDFORM. " variant_init

    FORM pai_of_selection_screen.

    IF NOT p_vari IS INITIAL.

    MOVE g_variant TO gx_variant.

    MOVE p_vari TO gx_variant-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

    EXPORTING

    i_save = g_save

    CHANGING

    cs_variant = gx_variant.

    g_variant = gx_variant.

    ELSE.

    PERFORM variant_init.

    ENDIF.

    ENDFORM. " pai_of_selection_screen

    CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

    EXPORTING

    is_variant = g_variant

    i_save = g_save

    IMPORTING

    e_exit = g_exit

    es_variant = gx_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 g_exit = space.

    p_vari = gx_variant-variant.

    ENDIF.

    ENDIF.

    AND pass this gx_variant to ALV Function module.

    Rewards points if helpful.

    Regards,

    Srinivas ch

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.