ALV Display Variant/Layout
The term Display Variant/Layout refers to display format for ABAP reports. As of Release 4.6C, these are called "layouts".
Layout gives more flexibility to customers for adjusting the report to meet various requirements. It gives the freedom to customers for modifying the output layout like change the column sequence, sorting the list, and hiding irrelevant data. It also gives flexibility over creating totals and subtotals.
Saving Layouts
Layouts can be saved for specific users or for all users. User-specific layouts are only visible to the users who have created them. Layouts for all users can be selected by every user using this report. These layouts always start with a forward slash in the name (for example, /Standard).The layouts are report-dependent and you can only create, change or delete them within the display of the respective ALV list. User-specific layouts can only be changed or deleted by the user who created them.
When calling the ALV display function REUSE_ALV_GRID_DISPLAY the check function parameter I_SAVE determines whether the layout can be saved as user-specific, for all users or can be saved in both types.
'X' Global Saving
'U' User Specific Saving
'A' Corresponds to X and U
Transporting Layouts
You can transport layouts for all users using the layout administration. You create a Customizing request for this. You cannot transport user-specific layouts. However, you can import both from another client. You can also access this function using the layout administration.
Important Function Modules Used For ALV Display Variant Processing
REUSE_ALV_VARIANT_DEFAULT_GET
The variants in the list display can be both user-specific and general. The user can programmatically set the initial (default) variant for list display. The default variant can be found using the function module
REUSE_ALV_VARIANT_F4
The user can choose from the list of existing variants using the function module. The function module returns the possible entry help for variants.
LVC_VARIANT_EXISTENCE_CHECK
Check for the existence of the variant passed to the program, can be used for validating the input variant.
Sample Program showing the functionalities
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'*&---------------------------------------------------------------------* *& Report ZFR_VARIENT *& *&---------------------------------------------------------------------* *& This is a sample program for passing display variant for an ALV *& Report form the selection with F4 help and validation to check the *& existance of the passed *&---------------------------------------------------------------------* REPORT zfr_varient. TABLES : sflight. TYPE-POOLS : slis. **INTERNAL TABLE DECLARTION DATA : wa_sflight TYPE sflight, it_sflight TYPE TABLE OF sflight. **DATA DECLARTION DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE, gd_layout TYPE slis_layout_alv, gd_repid LIKE sy-repid, g_save TYPE c VALUE 'X', g_variant TYPE disvariant, gx_variant TYPE disvariant, g_exit TYPE c, ispfli TYPE TABLE OF spfli. * To understand the importance of the following parameter, click here. **SELECTION SCREEN DETAILS SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002 . PARAMETERS: variant LIKE disvariant-variant. SELECTION-SCREEN END OF BLOCK b1. **GETTING DEFAULT VARIANT INITIALIZATION. gx_variant-report = sy-repid. 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. variant = gx_variant-variant. ENDIF. ** F4 Help for Varient AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant. **-- Display all existing variants g_variant-report = sy-repid. * Utilizing the name of the report, this function module will search for a list of * variants and will fetch the selected one into the parameter field for 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. variant = gx_variant-variant. ENDIF. ENDIF. **PERFORM DECLARATIONS START-OF-SELECTION. PERFORM data_retrivel. PERFORM build_fieldcatalog. PERFORM check_variant. PERFORM display_alv_report. *&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_fieldcatalog . fieldcatalog-fieldname = 'CARRID'. fieldcatalog-seltext_m = 'Airline Code'. fieldcatalog-col_pos = 0. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'CONNID'. fieldcatalog-seltext_m = 'Flight Connection Number'. fieldcatalog-col_pos = 1. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'FLDATE'. fieldcatalog-seltext_m = 'Flight date'. fieldcatalog-col_pos = 2. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'PRICE'. fieldcatalog-seltext_m = 'Airfare'. fieldcatalog-col_pos = 3. fieldcatalog-outputlen = 20. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. ENDFORM. " BUILD_FIELDCATALOG *&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* FORM display_alv_report . gd_repid = sy-repid. g_variant-variant = variant. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = gd_repid i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM i_callback_user_command = 'USER_COMMAND' it_fieldcat = fieldcatalog[] i_save = 'X' is_variant = g_variant TABLES t_outtab = it_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. "DISPLAY_ALV_REPORT" DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* *& Form DATA_RETRIVEL *&---------------------------------------------------------------------* FORM data_retrivel . SELECT * FROM sflight INTO TABLE it_sflight. ENDFORM. " DATA_RETRIVEL *-------------------------------------------------------------------* * Form TOP-OF-PAGE * *-------------------------------------------------------------------* * ALV Report Header * *-------------------------------------------------------------------* FORM top-of-page. *ALV Header declarations DATA: t_header TYPE slis_t_listheader, wa_header TYPE slis_listheader, t_line LIKE wa_header-info, ld_lines TYPE i, ld_linesc(10) TYPE c. * Title wa_header-typ = 'H'. wa_header-info = 'SFLIGHT Table Report'. APPEND wa_header TO t_header. CLEAR wa_header. * Date wa_header-typ = 'S'. wa_header-key = 'Date: '. CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum(4) INTO wa_header-info. "Today's date APPEND wa_header TO t_header. CLEAR: wa_header. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = t_header. ENDFORM. "Top-of-page *&---------------------------------------------------------------------* *& Form CHECK_VARIANT *&---------------------------------------------------------------------* FORM check_variant . g_variant-variant = variant. g_variant-report = sy-repid. CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK' "Check for display variant EXPORTING i_save = space "Variants Can be Saved CHANGING cs_variant = g_variant "Variant information EXCEPTIONS wrong_input = 1 "Inconsistent input parameters not_found = 2 "Variant not found program_error = 3 "Program Errors . " LVC_VARIANT_EXISTENCE_CHECK IF sy-subrc = 2. MESSAGE 'Display Variant Not Found, Displaying Default Variant' TYPE 'S'. ENDIF. 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. variant = gx_variant-variant. ENDIF. ENDFORM. "CHECK_VARIANT
2 Comments
Unknown User (ri3xzs2)
hello sir ,
How can i questions in this community and where i have to post querres ?
Former Member
Thanx....