Default variants in ALV

hello all,
can someone kindly tell me how to use the FM
"REUSE_ALV_VARIANT_DEFAULT_GET " in ALV for getting the default variant on the selection screen. what are the paameters to be specified????
thanks in adance,
seenu

Hello,
Check this code:
DATA : g_r_disp_variant TYPE disvariant.
SELECTION-SCREEN BEGIN OF BLOCK variant WITH FRAME TITLE text-003.
PARAMETERS:  p_varian LIKE disvariant-variant DEFAULT '/STANDARD'.
SELECTION-SCREEN END OF BLOCK variant.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varian.
  PERFORM show_existing_display_variants.
*&      Form  SHOW_EXISTING_DISPLAY_VARIANTS
*       text
*  -->  p1        text
*  <--  p2        text
FORM show_existing_display_variants.
  g_r_disp_variant-report = sy-repid.
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
       EXPORTING
            is_variant    = g_r_disp_variant
            i_save        = 'A'
       IMPORTING
            es_variant    = g_r_disp_variant
       EXCEPTIONS
            not_found     = 1
            program_error = 2
            OTHERS        = 3.
  IF sy-subrc = 0.
    p_varian = g_r_disp_variant-variant.
  ENDIF.
ENDFORM.                               " SHOW_EXISTING_DISPLAY_VARIANTS
*form get_output
  g_repid = sy-repid.
*  display variant
  g_r_disp_variant-report = sy-repid.
  IF NOT p_varian IS INITIAL.
    g_r_disp_variant-variant = p_varian.
  ENDIF.
*get_output
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program = g_repid
            i_grid_title       = 'PRICE COMPARISON REPORT:'
            is_layout          = it_layout
            it_fieldcat        = it_fldcat
            is_variant         = g_r_disp_variant
            i_default          = 'X'
            i_save             = 'A'
       TABLES
            t_outtab           = g_t_itab_alv
       EXCEPTIONS
            program_error      = 1
            OTHERS             = 2.
REgards,
Vasanth

Similar Messages

  • Change default variant in ALV grid on runtime

    Hello colleagues,
    where is the place in a code (CL_ALV_VARIANT, CL_GUI_ALV_GRID, ...) where I can change the deault layout. Customer require a modification which change default layout in ALV under specific circumstances.
    Kind regards
    Radim Benek

    It depend when these "specific circumstances" are occurring?
    Before displaying the ALV, then force the value of the variant used in set_table_for_first_display,
    CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'SFLIGHT'
        IS_VARIANT = GS_variant
        I_SAVE = X_SAVE
      CHANGING
        IT_OUTTAB = GT_SFLIGHT.
    If you want to simulate multiple "default variant" you should "mislead" the ALV by changing the report name used for storing variant (IS_VARIANT-REPORT) But in this case you will no longuer see every variant  when in the ALV, only those of the "report name" passed when setting for first display.
    Regards

  • ALV - How to default variant change.

    I have coded one report with ALV output.
    I have /DEFAULT variant in my ALV output  and the output contains 12 fields.
    When I execute the this report
    problem 1). How can i shift the 7th field to 12 th field and save as a new variant.
    Problem 2).If I rerun this new variant, how can I keep new set of arranged fields of new variant in the new order( means 7th field in 12 th position ).
    I mean in while re-running the program the fields are arranged in old manner (  7 th field in 7th position only - my functional consultant told me ) .
    Could you please help me ?

    are you sure that g_variant has got the correct value in it? Here's the components I use for programs that need the variant logic:
    PARAMETERS: p_varint LIKE disvariant-variant.
    initialization.
    perform alv_setup_layout_variant.
    AT SELECTION-SCREEN.
      PERFORM alv_validate_layout_variant.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varint.
      PERFORM alv_f4_for_layout_variant.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
    ...............etc
          i_save             = 'A'
          is_variant         = w_variant
    ............................etc
        EXCEPTIONS
          OTHERS             = 0.
    FORM alv_setup_layout_variant .
      DATA: lw_variant LIKE disvariant. " Layout structure
      CLEAR w_variant.
      w_variant-report = sy-repid.
      w_save = 'A'.
    Get default variant
      lw_variant = w_variant.
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
        EXPORTING
          i_save     = w_save
        CHANGING
          cs_variant = lw_variant
        EXCEPTIONS
          not_found  = 2.
      IF sy-subrc = 0.
        p_varint = lw_variant-variant.
      ENDIF.
    ENDFORM.                    " alv_setup_layout_variant
    FORM alv_validate_layout_variant.
      DATA: lw_variant LIKE disvariant. " Layout structure
      IF NOT p_varint IS INITIAL.
        lw_variant = w_variant.
        lw_variant-variant = p_varint.
        CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
          EXPORTING
            i_save     = w_save
          CHANGING
            cs_variant = lw_variant.
        w_variant = lw_variant.
      ENDIF.
    ENDFORM.                    " alv_validate_layout_variant
    FORM alv_f4_for_layout_variant.
      DATA: lw_variant LIKE disvariant.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
           EXPORTING
                is_variant          = w_variant
                i_save              = w_save
              it_default_fieldcat =
           IMPORTING
                e_exit              = w_exit
                es_variant          = lw_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.
    Store returned variant
        IF w_exit = space.
          p_varint = lw_variant-variant.
        ENDIF.
      ENDIF.
    ENDFORM.                    " alv_f4_for_layout_variant

  • Variant in ALV Reports

    hello all
    can anybody tell how to use variant in ALV Reports

    Look at the following example.
    report z_rock_ALV_example.
        * D-A-T-A D-E-C-L-A-R-A-T-I-O-N-S *
    tables: sflight.
              o
                    +
                          # TYPE-POOLS Definition
    **Includes the types and constants of a type group. Since the types and
    *constants specified in a type group have global validity, you cannot
    *use the statement within a FORM or FUNCTION.
    type-pools: slis.
    PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT.
              o
                    +
                          # ALV variables
                    +
                                      o Field Catalog structure
    data: ls_fieldcat type slis_fieldcat_alv, "Field Catalog list
              o
                    +
                                * Field Catalog table
    gt_fieldcat type slis_t_fieldcat_alv, "Field Catalog
              o
                    +
                                * Layout ( How you would like to see the output )
    gs_layout type slis_layout_alv, "List Layout
              o
                    +
                          # Report name
    g_repid like sy-repid,
    g_save(1) type c,
    g_exit(1) type c,
    g_variant like disvariant,
    gx_variant like disvariant.
              o
                    +
                          # Flight Info Internal table
    data: lt_sflight like sflight occurs 0 with header line.
        * C-O-N-S-T-A-N-T-S *
        * S-E-L-E-C-T-I-O-N S-C-R-E-E-N *
    selection-screen begin of block a with frame title text-100.
    select-options: s_carrid for sflight-carrid,
    s_connid for sflight-connid,
    s_fldate for sflight-fldate default sy-datum.
    selection-screen end of block a .
        * I-N-I-T-I-A-L-I-Z-A-T-I-O-N *
    initialization.
    g_repid = sy-repid.
              o
                    +
                          # Fill ALV field catalog
    perform initialize_fieldcat using gt_fieldcat[].
              o
                    +
                                * Build Events
        * perform build_eventtab using gt_events[].
              o
                    +
                          # Read the default variant
    perform initialize_variant.
        * A-T S-E-L-E-C-T-I-O-N S-C-R-E-E-N *
    at selection-screen on value-request for p_vari.
              o
                    +
                          # Display all existing variants
    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.
        * S-T-A-R-T O-F S-E-L-E-C-T-I-O-N *
    start-of-selection.
              o
                    +
                          # Read Flight information.
    perform read_flight_info.
              o
                    +
                          # Fill ALV field catalog and display report.
    if not lt_sflight[] is initial.
    perform dislay_alv_report.
    endif.
    ======================================================================
        * FORMS / SUB ROUTINES *
    *======================================================================
    *& Form initialize_fieldcat
        * text
        * -->P_GT_FIELDCAT[] text
    form initialize_fieldcat using l_fieldcat type slis_t_fieldcat_alv.
    clear ls_fieldcat.
        * Air line
    ls_fieldcat-fieldname = 'CARRID'.
    ls_fieldcat-key = 'X'.
    ls_fieldcat-col_pos = 1.
    ls_fieldcat-seltext_s = 'Airline'.
    ls_fieldcat-seltext_l = 'Airline'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Flight Number
    ls_fieldcat-fieldname = 'CONNID'.
    ls_fieldcat-key = 'X'.
    ls_fieldcat-col_pos = 2.
    ls_fieldcat-seltext_s = 'Flight Number'.
    ls_fieldcat-seltext_l = 'Flight Number'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Flight date
    ls_fieldcat-fieldname = 'FLDATE'.
    ls_fieldcat-key = 'X'.
    ls_fieldcat-col_pos = 3.
    ls_fieldcat-seltext_s = 'Flight date'.
    ls_fieldcat-seltext_l = 'Flight date'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Airfare
    ls_fieldcat-fieldname = 'PRICE'.
    ls_fieldcat-col_pos = 4.
    ls_fieldcat-do_sum = 'X'.
    ls_fieldcat-seltext_s = 'Airfare'.
    ls_fieldcat-seltext_l = 'Airfare'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Local Currency
    ls_fieldcat-fieldname = 'CURRENCY'.
    ls_fieldcat-col_pos = 5.
    ls_fieldcat-seltext_s = 'Local Currency'.
    ls_fieldcat-seltext_l = 'Local Currency'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Plane Type
    ls_fieldcat-fieldname = 'PLANETYPE'.
    ls_fieldcat-col_pos = 6.
    ls_fieldcat-seltext_s = 'Plane type'.
    ls_fieldcat-seltext_l = 'Plane type'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Maximum capacity
    ls_fieldcat-fieldname = 'SEATSMAX'.
    ls_fieldcat-col_pos = 7.
    ls_fieldcat-seltext_s = 'Max. seats'.
    ls_fieldcat-seltext_l = 'Max. seats'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Occupied seats
    ls_fieldcat-fieldname = 'SEATSOCC'.
    ls_fieldcat-col_pos = 8.
    ls_fieldcat-seltext_s = 'Seats occupied'.
    ls_fieldcat-seltext_l = 'Seats occupied'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Total
    ls_fieldcat-fieldname = 'PAYMENTSUM'.
    ls_fieldcat-col_pos = 9.
    ls_fieldcat-do_sum = 'X'.
    ls_fieldcat-seltext_s = 'Total amount'.
    ls_fieldcat-seltext_l = 'Total amount'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Total
    ls_fieldcat-fieldname = 'PAYMENTSUM'.
    ls_fieldcat-col_pos = 9.
    ls_fieldcat-do_sum = 'X'.
    ls_fieldcat-seltext_s = 'Total amount'.
    ls_fieldcat-seltext_l = 'Total amount'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Max. Capacity, Buss. Class
    ls_fieldcat-fieldname = 'SEATSMAX_B'.
    ls_fieldcat-col_pos = 10.
    ls_fieldcat-seltext_s = 'Max.Buss.class cap.'.
    ls_fieldcat-seltext_l = 'Max.Buss.class cap.'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Max. occupancy, Buss. Class
    ls_fieldcat-fieldname = 'SEATSOCC_B'.
    ls_fieldcat-col_pos = 11.
    ls_fieldcat-seltext_s = 'Max.Bus.CL.occupied'.
    ls_fieldcat-seltext_l = 'Max.Bus.CL.occupied'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Max. Capacity, First. Class
    ls_fieldcat-fieldname = 'SEATSMAX_F'.
    ls_fieldcat-col_pos = 12.
    ls_fieldcat-seltext_s = 'Max.Buss.class cap.'.
    ls_fieldcat-seltext_l = 'Max.Buss.class cap.'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
        * Max. occupancy, First. Class
    ls_fieldcat-fieldname = 'SEATSOCC_F'.
    ls_fieldcat-col_pos = 13.
    ls_fieldcat-seltext_s = 'Max.Bus.CL.occupied'.
    ls_fieldcat-seltext_l = 'Max.Bus.CL.occupied'.
    append ls_fieldcat to l_fieldcat.
    clear ls_fieldcat.
    ENDFORM. " initialize_fieldcat
    *& Form read_flight_info
        * text
        * --> p1 text
        * <-- p2 text
    FORM read_flight_info .
    refresh lt_sflight.
    clear lt_sflight.
              o
                    +
                          # Read data from SFLIGHT table
    select *
    from SFLIGHT
    into table lt_sflight
    where carrid in s_carrid
    and connid in s_connid
    and fldate in s_fldate.
    if sy-subrc <> 0.
    message e208(00) with text-101.
    endif.
    ENDFORM. " read_flight_info
    *& Form dislay_alv_report
        * text
        * --> p1 text
        * <-- p2 text
    FORM dislay_alv_report .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
        * I_INTERFACE_CHECK = ' '
        * I_BYPASSING_BUFFER =
        * I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = g_repid
        * I_CALLBACK_PF_STATUS_SET = ' '
        * I_CALLBACK_USER_COMMAND = ' '
    I_STRUCTURE_NAME = 'sflight'
        * IS_LAYOUT =
    IT_FIELDCAT = gt_fieldcat
        * IT_EXCLUDING =
        * IT_SPECIAL_GROUPS =
        * IT_SORT =
        * IT_FILTER =
        * IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = 'A'
    IS_VARIANT = GX_VARIANT
        * IT_EVENTS =
        * IT_EVENT_EXIT =
        * IS_PRINT =
        * IS_REPREP_ID =
        * I_SCREEN_START_COLUMN = 0
        * I_SCREEN_START_LINE = 0
        * I_SCREEN_END_COLUMN = 0
        * I_SCREEN_END_LINE = 0
        * IMPORTING
        * E_EXIT_CAUSED_BY_CALLER =
        * ES_EXIT_CAUSED_BY_USER =
    TABLES
    T_OUTTAB = lt_sflight
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2
    IF SY-SUBRC 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " dislay_alv_report
    *& Form initialize_variant
        * text
        * --> p1 text
        * <-- p2 text
    FORM initialize_variant .
    g_save = 'A'.
    clear g_variant.
    g_variant-report = g_repid.
    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.
    ENDFORM. " initialize_variant
    Regards,
    Rock.

  • What is the button to change the variant in alv?

    Hi guys,
              can u tell me  is there any button to change the variant in alv?. what is tanscation varient in report , hw it will used.

    Hi
    The ALV Grid Control is a tool with which you can output non-hierarchical lists in a
    standardized format. The list data is displayed as a table on the screen.
    The ALV Grid Control offers a range of interactive standard list functions that users need
    frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list,
    export list (in different formats), and so on. These functions are implemented in the
    proxy object class. You as the programmer have the possibility to turn off functions not
    needed. In most cases the implementations of the standard functions provided by the
    control are sufficient. However, if required, you can adjust these implementations to
    meet application-specific needs.
    You can add self-defined functions to the toolbar, if necessary.
    The ALV Grid Control allows users to adjust the layout of lists to meet their individual
    requirements (for example, they can swap columns, hide columns, set filters for the
    data to be displayed, calculate totals, and so on). The settings (list customizing) made
    by a specific user are called a display variant. Display variants can be saved on a userspecific
    or on a global basis. If such display variants exist for a list, they can be offered
    to the user for selection. If a display variant is set as the default variant, the associated
    list is always displayed based on the settings of this variant.
    <b>2. REUSE_ALV_LIST_DISPLAY
    REUSE_ALV_GRID_DISPLAY
    REUSE_ALV_FIELDCATALOG_MERGE
    REUSE_ALV_COMMENTARY_WRITE</b>
    3. Use of Field Catalog is to determines the technical properties & add formating information of the column.
    6. all the definition of internal table, structure, constants are declared in a type-pool called SLIS.
    7.fieldcat-fieldname
    fieldcat-ref_fieldname
    fieldcat-tabname
    fieldcat-seltext_m
    5. Form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield.
    Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.
    In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.
    The report output can contain up to 90 columns in the display with the wide array of display options.
    The commonly used ALV functions used for this purpose are;
    <b>1. REUSE_ALV_VARIANT_DEFAULT_GET
    2. REUSE_ALV_VARIANT_F4
    3. REUSE_ALV_VARIANT_EXISTENCE
    4. REUSE_ALV_EVENTS_GET
    5. REUSE_ALV_COMMENTARY_WRITE
    6. REUSE_ALV_FIELDCATALOG_MERGE
    7. REUSE_ALV_LIST_DISPLAY
    8. REUSE_ALV_GRID_DISPLAY
    9. REUSE_ALV_POPUP_TO_SELECT</b>
    Purpose of the above Functions are differ not all the functions are required in all the ALV Report.
    But either no.7 or No.8 is there in the Program.
    How you call this function in your report?
    After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.
    Then use follwing function module.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = 'Prog.name'
    I_STRUCTURE_NAME = 'I_ITAB'
    I_DEFAULT = 'X'
    I_SAVE = 'A'
    TABLES
    T_OUTTAB = I_ITAB.
    IF SY-SUBRC <> 0.
    WRITE: 'SY-SUBRC: ', SY-SUBRC .
    ENDIF.
    ENDFORM. " GET_FINAL_DATA
    The object F_IT_ALV has a field, the activity ACTVT, which can
    contain four permitted values: 01, 02, 03 and 70. Each of the
    activities 01, 02 and 70 controls the availability of particular
    functions (in the menu and the toolbar) of the ALV line item list:
    a) 01: "Settings -> Display variant -> Save..."
    b) 02: "Settings -> Display variant -> Current..." and
    "Settings -> Display variant -> Current header rows "
    c) 70: "Settings -> Display variant -> Administration..."
    Activity 03 corresponds to the minimum authorization, which is the
    most restricted one: The user can only select layouts which have
    been configured already. In particular, all of the other functions
    named above are inactive with activity 03.
    Now if you want to permit a user to change the column selection and
    the headers as well as to save the layout thus created, for example,
    but if you do not want to permit the user to administrate the
    layouts, you grant him or her the authorization for activities 01
    and 02.
    Check this link it will be mosty usefull for u
    http://www.sap-img.com/fu017.htm
    Reward all helpfull answers
    Regards
    Pavan

  • Variant in alv

    hi can anyone explain what is this 3 function module
    REUSE_ALV_VARIANT_EXISTENCE
    REUSE_ALV_VARIANT_DEFAULT_GET
    REUSE_ALV_VARIANT_F4
    i have a parameter variant on the selection screen so that user will be able to launch report with a default layout variant
    please give me an example where only this is implemented with list alv

    Hi
    See the doc of each fun module
    REUSE_ALV_VARIANT_DEFAULT_GET
    Read default display variant (description only, w/o field catalog)
    Functionality
    Provides the default variant for the list specified in the structure parameter CS_VARIANT of a program.
    Parameters
    I_SAVE
    CS_VARIANT
    Exceptions
    WRONG_INPUT
    NOT_FOUND
    PROGRAM_ERROR
    REUSE_ALV_VARIANT_EXISTENCE
    Checks whether a display variant exists
    Functionality
    This function module checks the existence in the database of a display variant passed in the interface.
    Parameters
    I_SAVE
    CS_VARIANT
    Exceptions
    WRONG_INPUT
    NOT_FOUND
    PROGRAM_ERROR
    REUSE_ALV_VARIANT_F4
    Display variant selection dialog box
    Functionality
    Possible entries help, if the variant is defined explicitly as an input field on a screen. The selection must be specified by at least partially filling the parameter structure IS_VARIANT.
    Parameters
    IS_VARIANT
    I_TABNAME_HEADER
    I_TABNAME_ITEM
    IT_DEFAULT_FIELDCAT
    I_SAVE
    I_DISPLAY_VIA_GRID
    E_EXIT
    ES_VARIANT
    Exceptions
    NOT_FOUND
    PROGRAM_ERROR
    CS_VARIANT is the structure which have the following fields data
    ABAP Program Name
    Mgt. ID for repeated calls from the same program
    Logical group name
    User name for user-specific storage
    Layout
    Description for layout
    Dependent variant entry vector
    check this with example also...
    *& Report  ZBC_ALV_EXAMPLE                                             *
    This program explains how we can use simple ALV functions to make    *
    reporting easy and looks pretty
    Programmer        : Venkat Reddy           ETA                       *
    Date              : 10/02/04                                         *
    Maintenance Log                                                      *
    Changed By      Date         Transport#   Description                *
    Venkat Reddy    10/02/04     EGD913575    Changed program to avoid   *
    REPORT  ZBC_ALV_EXAMPLE.
                    D-A-T-A  D-E-C-L-A-R-A-T-I-O-N-S                     *
    tables:  sflight.
    **-- TYPE-POOLS Definition
    **Includes the types and constants of a type group. Since the types and
    *constants specified in a type group have global validity, you cannot
    *use the statement within a FORM or FUNCTION.
    type-pools: slis.
    PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT.
    **-- ALV variables
    *****- Field Catalog structure
    data: ls_fieldcat     type slis_fieldcat_alv,    "Field Catalog list
    **--- Field Catalog table
          gt_fieldcat     type slis_t_fieldcat_alv,  "Field Catalog
    **--- Layout ( How you would like to see the output )
          gs_layout       type slis_layout_alv,       "List Layout
    **--  Report name
          g_repid         like sy-repid,
           g_save(1)           type c,
          g_exit(1)           type c,
          g_variant           like disvariant,
          gx_variant          like disvariant.
    **-- Flight Info Internal table
    data: lt_sflight like sflight occurs 0 with header line.
                    C-O-N-S-T-A-N-T-S                                    *
                    S-E-L-E-C-T-I-O-N  S-C-R-E-E-N                       *
    selection-screen begin of block a with frame title text-100.
    select-options: s_carrid  for  sflight-carrid,
                    s_connid  for  sflight-connid,
                    s_fldate  for  sflight-fldate default sy-datum.
    selection-screen end of block a .
                    I-N-I-T-I-A-L-I-Z-A-T-I-O-N                          *
    initialization.
      g_repid = sy-repid.
    **-- Fill ALV field catalog
      perform initialize_fieldcat using gt_fieldcat[].
    ***-- Build Events
    perform build_eventtab using gt_events[].
    **-- Read the default variant
      perform initialize_variant.
                    A-T  S-E-L-E-C-T-I-O-N  S-C-R-E-E-N                  *
    at selection-screen on value-request for p_vari.
    **-- Display all existing variants
      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.
                    S-T-A-R-T  O-F  S-E-L-E-C-T-I-O-N                    *
    start-of-selection.
    **-- Read Flight information.
    perform read_flight_info.
    **-- Fill ALV field catalog and display report.
      if not lt_sflight[] is initial.
        perform dislay_alv_report.
      endif.
    ======================================================================
                    FORMS / SUB ROUTINES                                 *
    *======================================================================
    *&      Form  initialize_fieldcat
          text
         -->P_GT_FIELDCAT[]  text
    form initialize_fieldcat using l_fieldcat type slis_t_fieldcat_alv.
      clear ls_fieldcat.
    Air line
      ls_fieldcat-fieldname   = 'CARRID'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-col_pos     = 1.
      ls_fieldcat-seltext_s   = 'Airline'.
      ls_fieldcat-seltext_l   = 'Airline'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Flight Number
      ls_fieldcat-fieldname   = 'CONNID'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-col_pos     = 2.
      ls_fieldcat-seltext_s   = 'Flight Number'.
      ls_fieldcat-seltext_l   = 'Flight Number'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Flight date
      ls_fieldcat-fieldname   = 'FLDATE'.
      ls_fieldcat-key         = 'X'.
      ls_fieldcat-col_pos     = 3.
      ls_fieldcat-seltext_s   = 'Flight date'.
      ls_fieldcat-seltext_l   = 'Flight date'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Airfare
      ls_fieldcat-fieldname   = 'PRICE'.
      ls_fieldcat-col_pos     = 4.
      ls_fieldcat-do_sum      = 'X'.
      ls_fieldcat-seltext_s   = 'Airfare'.
      ls_fieldcat-seltext_l   = 'Airfare'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Local Currency
      ls_fieldcat-fieldname   = 'CURRENCY'.
      ls_fieldcat-col_pos     = 5.
      ls_fieldcat-seltext_s   = 'Local Currency'.
      ls_fieldcat-seltext_l   = 'Local Currency'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Plane Type
      ls_fieldcat-fieldname   = 'PLANETYPE'.
      ls_fieldcat-col_pos     = 6.
      ls_fieldcat-seltext_s   = 'Plane type'.
      ls_fieldcat-seltext_l   = 'Plane type'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Maximum capacity
      ls_fieldcat-fieldname   = 'SEATSMAX'.
      ls_fieldcat-col_pos     = 7.
      ls_fieldcat-seltext_s   = 'Max. seats'.
      ls_fieldcat-seltext_l   = 'Max. seats'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Occupied seats
      ls_fieldcat-fieldname   = 'SEATSOCC'.
      ls_fieldcat-col_pos     = 8.
      ls_fieldcat-seltext_s   = 'Seats occupied'.
      ls_fieldcat-seltext_l   = 'Seats occupied'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Total
      ls_fieldcat-fieldname   = 'PAYMENTSUM'.
      ls_fieldcat-col_pos     = 9.
      ls_fieldcat-do_sum     = 'X'.
      ls_fieldcat-seltext_s   = 'Total amount'.
      ls_fieldcat-seltext_l   = 'Total amount'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Total
      ls_fieldcat-fieldname   = 'PAYMENTSUM'.
      ls_fieldcat-col_pos     = 9.
      ls_fieldcat-do_sum     = 'X'.
      ls_fieldcat-seltext_s   = 'Total amount'.
      ls_fieldcat-seltext_l   = 'Total amount'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Max. Capacity, Buss. Class
      ls_fieldcat-fieldname   = 'SEATSMAX_B'.
      ls_fieldcat-col_pos     = 10.
      ls_fieldcat-seltext_s   = 'Max.Buss.class cap.'.
      ls_fieldcat-seltext_l   = 'Max.Buss.class cap.'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Max. occupancy, Buss. Class
      ls_fieldcat-fieldname   = 'SEATSOCC_B'.
      ls_fieldcat-col_pos     = 11.
      ls_fieldcat-seltext_s   = 'Max.Bus.CL.occupied'.
      ls_fieldcat-seltext_l   = 'Max.Bus.CL.occupied'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Max. Capacity, First. Class
      ls_fieldcat-fieldname   = 'SEATSMAX_F'.
      ls_fieldcat-col_pos     = 12.
      ls_fieldcat-seltext_s   = 'Max.Buss.class cap.'.
      ls_fieldcat-seltext_l   = 'Max.Buss.class cap.'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    Max. occupancy, First. Class
      ls_fieldcat-fieldname   = 'SEATSOCC_F'.
      ls_fieldcat-col_pos     = 13.
      ls_fieldcat-seltext_s   = 'Max.Bus.CL.occupied'.
      ls_fieldcat-seltext_l   = 'Max.Bus.CL.occupied'.
      append ls_fieldcat to l_fieldcat.
      clear ls_fieldcat.
    ENDFORM.                    " initialize_fieldcat
    *&      Form  read_flight_info
          text
    -->  p1        text
    <--  p2        text
    FORM read_flight_info .
    refresh lt_sflight.
    clear   lt_sflight.
    **-- Read data from SFLIGHT table
      select *
        from SFLIGHT
        into table lt_sflight
        where carrid in s_carrid
         and  connid in s_connid
         and  fldate in s_fldate.
    if sy-subrc <> 0.
       message e208(00) with text-101.
    endif.
    ENDFORM.                    " read_flight_info
    *&      Form  dislay_alv_report
          text
    -->  p1        text
    <--  p2        text
    FORM dislay_alv_report .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
       I_CALLBACK_PROGRAM              =  g_repid
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
       I_STRUCTURE_NAME                =  'sflight'
      IS_LAYOUT                      =
       IT_FIELDCAT                     =  gt_fieldcat
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
       I_DEFAULT                      = 'X'
       I_SAVE                         = 'A'
      IS_VARIANT                     = GX_VARIANT
      IT_EVENTS                      =
      IT_EVENT_EXIT                  =
      IS_PRINT                       =
      IS_REPREP_ID                   =
      I_SCREEN_START_COLUMN          = 0
      I_SCREEN_START_LINE            = 0
      I_SCREEN_END_COLUMN            = 0
      I_SCREEN_END_LINE              = 0
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      TABLES
        T_OUTTAB                       = lt_sflight
    EXCEPTIONS
       PROGRAM_ERROR                  = 1
       OTHERS                         = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.                    " dislay_alv_report
    *&      Form  initialize_variant
          text
    -->  p1        text
    <--  p2        text
    FORM initialize_variant .
    g_save = 'A'.
      clear g_variant.
      g_variant-report = g_repid.
      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.
    ENDFORM.                    " initialize_variant
    regards,
    venkat.

  • Report always shows default variant

    Hello,
    I've got a report where we can choose a variant in the selection screen.
    SELECTION-SCREEN BEGIN OF BLOCK SEL2 WITH FRAME TITLE TEXT-002.
    PARAMETERS p_layout TYPE slis_vari.
    SELECTION-SCREEN END OF BLOCK SEL2.
    I've got it setup so that when the user runs the report, the field p_layout is filled with his default variant or if he has none it's empty.
    My problem is when the field is empty the result ALV is always shown with the default variant.
    For example:
    User has 2 variants - SAV1 and SAV2 (default).
    User enters selection screen and p_layout is filled with SAV2.
    Scenario 1:
    User presses F8 and the ALV is shown with the variant SAV2
    Scenario 2:
    User changes p_layout to SAV1 and presses F8. ALV is shown with SAV1 variant
    Scenario 3:
    User emptys p_layout (p_layout IS INITIAL), presses F8 and ALV is shown with SAV2 variant - the default one
    What can I do so that when p_layout IS INITIAL the ALV shows all the columns?
    This is how I define the layout:
           gr_layout = gr_alv->get_layout( ).
           MOVE sy-repid TO gs_layout_key-report.
           gr_layout->set_key( gs_layout_key ).
           gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
           gr_layout->set_default( 'X' ).
           gr_layout->set_initial_layout( p_layout ).
    F4 help for p_layout:
       ls_layout_key-report = sy-repid.
       ls_layout_info = cl_salv_layout_service=>f4_layouts( ls_layout_key ).
       p_layout = ls_layout_info-layout.
    Initialization of p_layout:
       gs_variant-report = sy-repid.
       CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
         EXPORTING
           I_SAVE        = 'A'
         CHANGING
           CS_VARIANT    = gs_variant
         EXCEPTIONS
           WRONG_INPUT   = 1
           NOT_FOUND     = 2
           PROGRAM_ERROR = 3
           OTHERS        = 4.
       IF sy-subrc = 2 OR sy-subrc = 0.
         p_layout = gs_variant-variant.
       ELSE.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
       ENDIF.
    the sy-subrc = 2 is there to prevent error if user has no layouts => p_layout stays empty
    Thank you in advance!

    Thank you Thanga Prakash for your help, it lead me to the an awnser.
    Even after I cleared the p_layout I still had the same issue but after reviewing the code once more I deleted the following line
    gr_layout->set_default( 'X' ).
    With this, if no layout was specified (p_layout IS INITIAL) the default variant was always called.

  • Handle variants in ALV.

    Hi,
             I am creating an interactive ALV lists.The basic list has default variant.
    when I dbl click contract in basic ALV the second ALV display the details.
    Both ALVs r created using REUSE_ALV_GRID_DISPLAY.
    in first FM I gave like
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_interface_check       = ' '
                i_buffer_active         = ' '
                i_callback_program      = g_repid
                i_callback_user_command = 'DO_MESSAGE'  "form
                i_grid_title            = l_header
                is_layout               = layt
                it_fieldcat             = tcat
                i_save                  = 'X'
           TABLES
                t_outtab                = itab
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
      CHECK NOT sy-subrc IS INITIAL.
    Then the second ALV FM
        fieldcat:
          1 'VBELN'    'CHAR'  10 'CONTRACT'(089)       ''    '' '',
          2 'BELNR'    'CHAR'  10 'DOCUMENT NUMBER'(090) 'X'   '' '',
          3 'BLDAT'    'DATS'  10 'DOC.DATE'(091)       ' '   '' '',
          8 'L_WTGBTR' 'CURR'   15 'AMOUNT'(092)         ' '   'R' 'X',
          5 'KEY'      'NUMC'  15 'KEY'(093)            ' '   '' '',
          6 'LTEXT'    'CHAR'  28 'DESCRIPTION'(094)    ' '   '' '',
          7 'CTGY'     'CHAR'   4 'CTGY'(095)           ' '   '' ''.
      ENDIF.
      gw_sort-fieldname = 'VBELN'.
      gw_sort-up        = 'X'.
      gw_sort-spos      = 1.
      gw_sort-subtot    = 'X'.
      APPEND gw_sort TO gt_sort.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_buffer_active         = ' '
                i_callback_program      = pgm
                i_callback_user_command = 'DISP_ITEM'
                is_layout               = gt_layout
                it_fieldcat             = gt_fieldcat
                it_sort                 = gt_sort
           TABLES
                t_outtab                = gt_covp
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
    when I pass I_SAVE = 'A' or 'U' or 'X' then the result will be displayed with
    single field.the other fields r hidden.That single field is displayed with length of 111ch.but its actual size is 10.
    without this its working fine.but I can't enable variants save button in second ALV.
    how to enable it.
    Regards,
    bala

    The problem is with the IS_VARIANT parameter. You must be passing the same values / no values to both the list.
    You should be using this parameter and differentiate between these list by passing different values to the HANDLE field for the different lists. Then you will have separate variants for each of the list.
    The value could be anything, as simple as FIRST and SECOND.
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • DB Table for Layout Variant in ALV report

    Please help me by providing the table name which will get an entry when we save Layout Variant in ALV(OO ALV grid) output.

    Hi,
    I have seen the table LTDX which is giving me the Variant names for a particular program. Hope this will help you.
    Database table is LTDX
    Database view is V_LTDX.
    Regards,
    Venaktesh

  • BEx workbook Default variant not working with Broadcaster

    Hi,
    We are broadcasting a BEx workbook, which has more than 1 queries. We have a default variant to populate all the input variables. But while broadcasting, this default variant is not populated sometimes, So the query returns wrong results. It happens randomly. I have checked broadcast logs also nothing unusual found. Can someone throw some light.
    Thanks

    Hi,
    We are broadcasting a BEx workbook, which has more than 1 queries. We have a default variant to populate all the input variables. But while broadcasting, this default variant is not populated sometimes, So the query returns wrong results. It happens randomly. I have checked broadcast logs also nothing unusual found. Can someone throw some light.
    Thanks

  • Default variant to be picked for QGA3 when run through QE01/QE02/QE03.

    Hi Gurus,
    I need help regarding one requirement, Our client want to have default variant which will have custom form name of selection screen of QGA3, along with the inspection lot number carried from QE01/QE02/QE03.
    Our client did not get convinced for any alternative like custom transaction code or transaction variant for QGA3, they want only during std t-code run only.
    I will explain the requirement once again, During QE01/QE02/QE03 when we click on "Inspection result print" it will take to QGA3 screen. The inspection lot is carry forward from QE01/QE02/QE03 to QGA3 screen and along with this the default variant also to be picked automatically .
    Thanks in advance for your help
    Nag.

    Explore function module exit EXIT_SAPLQEEM_022 & EXIT_SAPLQEEM_026

  • Create new transaction with default variant

    Dear all,
    I want to create a new tcode, which will be a replica of IW58 and save a default variant only in this replica.
    Is this possible? If yes how to do it please?
    Thanks a lot for your kind consideration
    David

    Maintain the variant you would like to use with IW58
    Goto SE80, navigate to your Customer Package (Z*), open the node "Transactions". Right Klick -> Create Transaction.
    Set a Transaction-Code and an apropriate Start Object (Most likely Dialog Transaction or Report Transaction). Assign the Report RIQMEL20.
    Then fill in the Field "Start with variant" by selecting the variant you would like to use.
    Hope that helps.

  • Variant in ALV selection screen

    Hi friends,
         How to protect a variant in ALV selection screen from changing or deleting by other users.
    Thanks,
    Rajesh

    Rajesh,
    You still need someone to be able to change the variant, right? That is what exactly PROTECT VARIANT does.
    If you select the field Protect variant, the variant can only be changed by the person who created it or last changed it.                         
    Regards,
    Ravi
    Note :Please mark the helpful answers  and close the thread if the quesiton is answered

  • User specific default variant in  a selectio screen

    Is it possible to provide an option to create user specific default variant in a selection screen?
    I have developed a custom report program. Now I want to allow users to choose one of their variants as default variant ?  Please help.

    Hi very Simple and easy solution:
    In SE93 when u are creating the transaction for the program use the option 'Start with variant' and give your own vaiant name for the program start. This will help you in starting your proam always with your default variant.
    Hope That Helps
    Anirban M.

  • To change the icon name displayed by default while an ALV is displayed.

    Hi Experts ,
    Need to change the icon name EXPORT displayed by default , while an ALV is displayed to Download to Excel.
    How can this be achieved?
    Regards.

    Hi,
    You can copy the Status 'Standard' of the program 'SAPLKKBL' and create a Z. Change the icon name in the Z pf-status as wished. Now in the event slis_ev_pf_status_set of 'REUSE_ALV_GRID_DISPLAY' set the PF-Status to the Z that u created.
    Regards,
    Nikhil

Maybe you are looking for