ALV In ABAP

ALV for ABAP Freshers
INTRODUCTION 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 following types of display are possible using ALV: 1. 2. 3. 4. List display Grid display Hierarchical display Block display

This document is aimed to introduce the reader to ALV Reports .It gives a brief overview about the various types of ALV displays and the different function modules used .It also provides screenshots of various types of ALV Display and sample code. PRE-REQUISITES: The reader should have a basic knowledge of ABAP Data dictionary ,Language constructs, working with tables ,simple report programming. ALV: What is ALV ALV is an acronym for ABAP List Viewer .It is a standard tool which enhances the readability of a report. Advantages of ALV: 1. Column alignment 2. Sorting 3. Subtotals 4. Downloading to excel or HTML format 5. Report analysis in graphical view 6. We can have our own layout set with our desired fields

1

ALV In ABAP 7. The various parameters in this function module: I_INTERFACE_CHECK I_BYPASSING_BUFFER I_BUFFER_ACTIVE I_CALLBACK_PROGRAM I_CALLBACK_PF_STATUS_SET I_CALLBACK_USER_COMMAND I_STRUCTURE_NAME IS_LAYOUT IT_FIELDCAT IT_EXCLUDING IT_SPECIAL_GROUPS IT_SORT IT_FILTER IS_SEL_HIDE I_DEFAULT I_SAVE IS_VARIANT IT_EVENTS IT_EVENT_EXIT IS_PRINT IS_REPREP_ID I_SCREEN_START_COLUMN I_SCREEN_START_LINE I_SCREEN_END_COLUMN I_SCREEN_END_LINE E_EXIT_CAUSED_BY_CALLER ES_EXIT_CAUSED_BY_USER T_OUTTAB 2 . Blocked. 1. Gives a good look and feel. List Display. We can present the data in what ever the format we want like list. Hierarchical. Tree and so on.ALV list display can be achieved using the function module ‘Reuse_alv_list_display’. List display Grid display Hierarchical display Block display All the different types of ALV displays can be achieved using function modules. Types of ALV: 1. 2. The function module outputs an internal table with any structure as a formatted one-line or multiple-line list. 9. Grid. 4. 3. structures and constants are declared in a type-pool called SLIS. We can use mailing services 8. In list display the output of ALV is in the form of a simple list (single line or several lines). All the definitions of internal tables.

g. 3.ALV In ABAP Among the above. t_layout-zebra =’x’. let us consider in detail some of the important and commonly used parameters 1. it is used to modify the appearance of columns in the output. 3a. IT_FIELDCAT –This is the most vital parameter which has to be imported to the alv display function module. it means that the alternate rows in the output will be colored dark and light.For example we have an internal table t_layout which is imported to the field IS_layout.Fieldcatalog can be generated either automatically or manually. 2. The following details will be commonly filled in the internal table. window_titlebar-: If t_layout-window_titlebar =’ ’ then the title of detail display popup window (which we get when double clicking a row) will be details: display. Declare t_layout as type slis_layout_alv. c. A field catalog is required for every ALV list output. if the column width is declared as 30 but in the output if the field is only 10 characters long. t_layout-colwidth_opt =’X’.The field catalog for the output table is builtup in the caller's coding. If t_layout-window_titlebar = ‘<title as we like>’ then that title will be displayed in the popup window.e. then the remaining space would be removed. This makes the output column width to increase or decrease as per the content width. The internal table passed to this parameter should be of type ‘slis_layout_alv’.The variable passed to this parameter should be of type SY-REPID. Field catalog contains descriptions of the list output fields (usually a subset of the internal output table fields). 3 . IS_LAYOUT-List layout specifications i. I_CALLBACK_PROGRAM –This denotes the program from which the function module is called .Automatic generation of field catalog: This can be achieved using the function module ’REUSE_ALV_FIELDCATALOG_MERGE’. b. When the field zebra equals to ‘X’.e. a.

The parameter specifies the relative column position of the field in the list output. The internal table to be output does not have the same structure as a Data Dictionary structure which is referred to in the internal table declaration using LIKE or INCLUDE STRUCTURE.60 Only relevant when the default relative column positions differ from the field catalog field sequence. 1 . Function group.ALV In ABAP The important parameters for this function module are: I_PROGRAM_NAME-Program from which the function module is called and which contains the exit routines. The program should always be a Report. the fields present in the output table and their positions are stored in a buffer . 4 . All fields in this structure need not be output. columns appear in the field catalog field sequence. If this parameter is initial for all field catalog entries. I_BUFFER_ACTIVE-For the same reason mentioned above. A multi-line list can also be defined by the user interactively if the default list is one-line. Module pool or Form routine pool (not an Include). Row_pos (row position) Value set: 0.3 Only relevant if the list output is to be multi-line (two or three lines) by default. I_BYPASSING_BUFFER-When the program is run for the first time. 2.So buffer is taken as a reference for successive executions. 1 .Manually populating the field catalog: Sometimes there is a need to fill in the field catalog manually under on of the following conditions 1. The parameter specifies the relative output line of the column in a multi-line list. Col_pos (column position) Value set: 0. 2. this parameter should hold the value ‘ ‘(space) 3b. This parameter should hold the value ‘X’ to bypass the buffer. Some of the commonly used details while populating a field catalog manually is: Positioning 1. I_INTERNAL_TABNAME-Name of the output internal table which will be displayed. The column order can be changed interactively by the user.

'Cxyz' = column is colored with a coded color: C: Color (coding must begin with C) X: color number (can range from 0 to 7) 0-background color 1-Blue 2-Gray 3-Yellow 4-Blue/Gray 5-Green 6-Red 5 .ALV In ABAP Identification 1. Outputlen (column width) Value set: 0 (initial). output table field name Only relevant for quantity columns with unit link. The field in FIELDCAT-CFIELDNAME must have its own field catalog entry. Emphasize (highlight columns in color) 'X' = column is colored with the default column highlight color. n For fields with a Data Dictionary link this parameter can be left initial.Name of the internal output table field which is described by this field catalog entry. Initial = column width is the output length of the referred Data Dictionary field (domain). n = column width is n characters. Fieldname (field name) Value set: internal output table field name (required parameter). Column output options 1. 3. NOTE: the fieldname must be given in UPPER CASE. Qfieldname (measurement unit field name) Value set: SPACE. Name of the internal output table field containing the measurement unit associated with the quantity field FIELDCAT-FIELDNAME. 'X' 'X' = kex field (key field output in color) Key fields can not be interactively hidden. Cfieldname (currency unit field name) Value set: SPACE. The field in FIELDCAT-QFIELDNAME must have its own field catalog entry. Key (key column) Value set: SPACE. For fields without a Data Dictionary link (program field) the parameter must be given the value of the desired field list output length (column width). 2. Link to currency unit 1. Name of the internal output table field containing the currency unit associated with the amount field FIELDCAT-FIELDNAME. Link to measurement unit 1. output table field name only relevant for amount columns with associated unit.

or F1 help which differs from the Data Dictionary help can be provided for a field with a Data Dictionary reference. Popups. Format column contents 1. 'L'. • • • • F1 HELP: Value set: SPACE. Independent justification of the column header is not possible. The texts are taken from the Data Dictionary for fields with a Data Dictionary reference. The 'long field label' is also used in display variant definition. The Data Dictionary texts are then ignored.ALV In ABAP 7-Orange y: bold(0=off. 'R'. using this parameter. Data Dictionary data element name F1 help can be provided for a program field without a Data Dictionary reference. If the user changes the column width interactively. If this is not desired. sort. The interactive function 'Optimize column width' takes account of both the field contents and the column headers if all field contents are shorter than the shortest column header. the column header text with the appropriate length is always used. Texts The following text parameters should be specified for program fields without a Data Dictionary reference. 'C' Only relevant for fields of data type CHAR or NUMC ' ' = default justification for this data type 'R' = right-justified output 'L' = left-justified output 'C' = centered output NOTE: The justification of the column header always follows the justification of the columns. etc. the text parameters can also be specified. 1=on) z: inverse(o=off. seltext_l (long field label) seltext_m (medium field label) seltext_s (short field label) reptext_ddic (header) 6 . the column width depends on the column header. 1=on) Example if we give fieldcat-emphasize = ‘C510’ Then green color will be displayed with intensified on. Just (justification) Value set: SPACE.

I_LIST_TYPE (type SLIS_LIST_TYPE) (Export Parameter) Pass any one of the following values 0 = simple list REUSE_ALV_LIST_DISPLAY 1 = hierarchical-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY 2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND 3 = hierarchical-sequential block list REUSE_ALV_BLOCK_LIST_HS_APPEND 2. Pass this modified internal table to the display function module through the corresponding parameter (IT_EVENTS explained earlier). The formatted simple header output at Top of Page can be output using the function module ‘REUSE_ALV_COMMENTARY_WRITE’. the documentation of the data element of the referred Data Dictionary field is output. skip etc. The table of possible events per list type can be initialized using the module REUSE_ALV_EVENTS_GET. 4. IT_EVENTS-This internal table tells the ALV. The function module contains the following parameters: 1. The FORM field will be blank when the FM returns the internal table. uline. We have to fill the name of the form in which we are going to handle a particular event in the FORM field corresponding to the EVENT in the internal table returned by the FM. The function module has the following import parameters: 1.We need to declare an internal table of type SLIS_T_LISTHEADER and pass it to 7 . Some of the most commonly used events in ALV are : • Top of page • Top of list • End of page • End of list • Set PF Status • User Command 1) TOP OF PAGE: The event gets triggered whenever the first output statement like write. ET_EVENTS (type SLIS_T_EVENT) (Import Parameter) This internal table is returned by the FM with the list of all possible CALLBACK events for the particular ALV display. IT_ LIST_COMMENTARY-This field is of type SLIS_T_LISTHEADER. which events are processed by the user CALLBACK. the documentation of the specified data element is displayed. is encountered. The NAME field will have the list of all the events that can be handled in ALV. This function module returns an internal table having two fields NAME and FORM.ALV In ABAP When F1 help is called for this field. If the FIELDCAT-ROLLNAME is initial for fields with a Data Dictionary reference.

e. • Action: Describes the action info.The internal table contains three fields namely TYPE. 2) TOP OF LIST: This event gets triggered only once at the start of ALV display.ALV In ABAP IT_LIST_COMMENTRY. TYP: Possible values are Header. You specify the size of the END-OF-PAGE area of list pages in the LINECOUNT parameter of the REPORT statement (e. Usually only one line. denoted by ‘H’. but end of page will be triggered at the end of every page in ALV. End of Page gets triggered when the ALV Report is displayed. formatted by type. If you explicitly specify a new page with NEWPAGE. KEY: String with keyword character output in combination with TYP =’S’. REPORT TEST LINE-COUNT 65(3)). 3) END-OF-PAGE: The END-OF-PAGE event is executed whenever processing reaches that area when formatting a list page or if the RESERVE statement detects that there is insufficient space remaining on the current page. but top of page will be triggered for every new page in ALV. the END-OF-PAGE area contains no lines and the event END-OF-PAGE is never executed. Top of List can never been seen in an ALV Report it comes only with the print out. 5) PF-STATUS: Sets a GUI (Graphical User Interface) status pfstat which can be up to 20 characters long. Selection and Action. Top of Page gets triggered when the ALV Report is displayed. END-OF-PAGE is ignored. denoted by ‘S’. 4)END OF LIST : This event gets triggered only once at the end of ALV display. 8 . If the standard setting LINE-COUNT 0 applies (i. the event END-OF-PAGE is not processed.Only the contents of INFO are output. There are many of these statuses in the GUI of a program. KEY is ignored. since no automatic new page follows.End of List comes out only when the ALV Report is printed. no restriction on the number of lines per page). Denoted by ‘A’. INFO: Information output in header. The current status is stored in the system field SY-PFKEY. KEY and INFO. Only the contents of INFO are output. Each one describes which functions are available and how you can select these via menus and menu bars or by pressing function keys or pushbuttons. If you do not define a size.g.Top of List comes out only when the ALV Report is printed. • Selection: It displays important header information. direct output via table. KEY is ignored. • Header: It is the list header. End of List can never been seen in an ALV Report it comes only with the print out.It usually consist of several entries.

ALV List is done with function module. Grid can be done with function module and also using OO concepts. In ALV Grid we have resizable column option but in ALV list this option is not present. GRID DISPLAY: Difference between ALV List and ALV Grid Display: 1. In grid we can display the headings and top-of-page by using parameters in function module.of-page. 5. In list we need to use events to display the headings and top. 4. 7. ALV List is display only but Grid can be made editable for entry purpose. In addition the following parameters are present I_CALLBACK_TOP_OF_PAGE I_CALLBACK_HTML_TOP_OF_PAGE I_CALLBACK_HTML_END_OF_LIST I_BACKGROUND_ID I_GRID_TITLE I_GRID_SETTINGS IT_ALV_GRAPHICS IT_HYPERLINK IT_ADD_FIELDCAT IT_EXCEPT_QINFO I_HTML_HEIGHT_TOP I_HTML_HEIGHT_END 2.ALV In ABAP A status remains valid for the duration of a transaction or until you set a new status. In ALV list display it is not possible to insert logos in top of page but in grid display logos can be inserted by calling the function module REUSE_ALV_COMMENTRY_WRITE. For ALV Grid display the function module “REUSE_ALV_GRID_DISPLAY” is used. 6. 2. The function module has all the parameters as discussed in the “REUSE_ALV_LIST_DISPLAY”. 6) USER-COMMAND: It describes what should happen when the user performs certain action like clicking of a button etc. ALV List can be displayed hierarchically but grid cannot be displayed hierarchically. The parameter ‘I_CALLBACK_TOP_OF_PAGE’ in the function module ‘REUSE_ALV_GRID_DISPLAY’ can be used for top of page in ALV Grid.The user command would be stored in sy-ucomm. 3. 9 .

If not sure.ALV In ABAP I_LOGO – We can upload logos in the ALV top of page using this parameter. Upon execution you would be prompted to give the file path details. The function module used for Hierarchical display is “REUSE_ALV_HIERSEQ_LIST_DISPLAY”. NOTE: Hierarchical display can only be used with List display. when the output needs to be refreshed then we can use selfield-refresh = 'X'. STEPS TO INCLUDE LOGO: Logo should be uploaded into application server using transaction 'OAER'. Object Key as the name of the Object u want to specify 5. Just upload which ever logo u want to display 6. REFRESHING THE ALV OUTPUT: After the display of the ALV output. Here sales order details can be the header data whereas them items in the sales order can be the item data. 3. 2. ->There is no clear cut definition that if so much data then go for list or vise versa but the developer has to take a call based on his experience. Like sales order and item details. scrolling down consumes a lot of resources / time if the volume of data to be displayed is high. where selfield is of type slis_selfield. Now you can use the same name in your ALV FM. The following parameters are present in the function module I_INTERFACE_CHECK I_CALLBACK_PROGRAM I_CALLBACK_PF_STATUS_SET I_CALLBACK_USER_COMMAND IS_LAYOUT IT_FIELDCAT 10 . ALV List is faster and better in case of huge volumes of data. What are the criteria to choose between the grid and list display. Give Class Name as PICTURES 3. then list is the better option. 1. -> Functions like sort. Go to Transaction OAER. 7. Class type as OT 4. ->Grid cannot handle high volumes. This module outputs two internal tables as a formatted hierarchical-sequential list. Hierarchical Display: Hierarchical display are used to display data that are related.

It is the name of the internal table in the program containing the output data of the highest hierarchy level. This structure contains the header and item table field names which link the two tables (shared key). 11 . 3. 4. I_STRUCTURE_NAME_HEADER-It is the internal output table (header) structure name. The foreign key field names of the header and item tables are usually identical. It is a mandatory parameter to be passed into the function module. It is the name of the internal table in the program containing the output data of the lowest hierarchy level. I_STRUCTURE_NAME_ITEM.It is the internal output table (item) structure name. Table field links. 5. Enter the foreign key field names in the fields KEYINFO-HEADERxx and KEYINFO-ITEMxx. I_TABNAME_ITEM-This is also a mandatory parameter. 2. I_TABNAME_HEADER – This a mandatory parameter to be passed into the function module. IS_KEYINFO –It represents the Header/position.ALV In ABAP IT_EXCLUDING IT_SPECIAL_GROUPS IT_SORT IT_FILTER IS_SEL_HIDE I_SCREEN_START_COLUMN I_SCREEN_START_LINE I_SCREEN_END_COLUMN I_SCREEN_END_LINE I_DEFAULT I_SAVE IS_VARIANT IT_EVENTS IT_EVENT_EXIT I_TABNAME_HEADER I_TABNAME_ITEM I_STRUCTURE_NAME_HEADER I_STRUCTURE_NAME_ITEM IS_KEYINFO IS_PRINT IS_REPREP_ID I_BYPASSING_BUFFER I_BUFFER_ACTIVE E_EXIT_CAUSED_BY_CALLER ES_EXIT_CAUSED_BY_USER T_OUTTAB_HEADER T_OUTTAB_ITEM Among these the parameters not discussed in list display are: 1.

I_INTERFACE_CHECK 2. I_CALLBACK_PF_STATUS_SET 3. I_CALLBACK_USER_COMMAND 4. 4. BLOCK DISPLAY: Blocked ALV is used if we have more than one report in the output. Naming the other key fields guarantees a stable item table sort sequence. REUSE_ALV_BLOCK_LIST_DISPLAY: This is used to display all the ALV’s in the block and has the following function modules: 1. I_TABNAME 4.e. It contains the following parameters: 1. The corresponding header table field (HEADERxx) must be SPACE. 3. IT_SORT 6. REUSE_ALV_BLOCK_LIST_DISPLAY 1. IS_PRINT 3.ALV In ABAP The item table has other key fields as well as the header table foreign key. We need to use three function modules for Block display. IS_LAYOUT 2. IT_EXCLUDING 2. These other key fields should also be named in this structure. I_SCREEN_START_COLUMN 4. REUSE_ALV_BLOCK_LIST_APPEND: This function module is used to append each ALV output required. I_SCREEN_START_LINE 5. REUSE_ALV_BLOCK_LIST_INIT: This function module is used to initialize the block ALV . REUSE_ALV_BLOCK_LIST_INIT 2. IT_FIELDCAT 3. 12 . I_TEXT If we want to display the contents of five internal tables in the output then we should call “REUSE_ALV_BLOCK_LIST_APPEND” five times. REUSE_ALV_BLOCK_LIST_APPEND 3. The variants are used to set default properties Of ALV output.This looks like a simple report but this report has the function of sorting and filtering only. IT_EVENTS 5.It contains the following parameters: 1.) if there are multiple internal tables with data to be displayed as single block then we go for block ALV. I_SCREEN_END_LINE ALV Variants: ALV provides the user with the flexibility of selecting the displaying only the desired column from the output. I_CALLBACK_PROGRAM 2. 1. (i. I_SCREEN_END_COLUMN 6.

13 . If ‘X’ is passed standard save only is possible. 3. the list of all fields in the display is shown in the new popup screen.Reuse_alv_variant_default_get:. ‘X’ and SPACE.Used to fetch the default ALV variant. If the value passed is ‘U’ then the layout should only be user specific.ALV In ABAP The parameter i_save in the function module ‘REUSE_ALV_LIST_DISPLAY’ and ‘REUSE_ALV_GRID_DISPLAY’ specifies the mode in which the display variant can be saved.’U’.Used to check if the selected variant is valid or not. The parameter i_save can have the values ‘A’.This displays the variant selection dialog box. Then we can hide the desired fields by selecting that field and clicking on the hide selected field’s button as shown in the screenshot above. On clicking the layout icon in the output. If the value ‘A’ is passed to this parameter then user can save the output variant user specifically or as standard variant. If the value passed is SPACE then no save is done. Reuse_alv_variant_existence:. 2. Reuse_alv_variant_f4:. The common function modules related to ALV Variants are 1.

ALV In ABAP Then goto Settings->layout->save to save the layout. Sample ALV Outputs: ALV List Display: ALV Grid Display: 14 .

ALV In ABAP ALV Hierarchial Display: ALV Block Display 15 .

SAP Dialog Box Container The SAP Dialog Box container allows you to display controls in a modal dialog box or full screen. a. Class: CL_GUI_CUSTOM_CONTAINER b. we can have two grid displays in one screen whereas by using the classical ALV function modules two blocks of ALV output can be obtained only as two lists. Class: CL_GUI_DIALOGBOX_CONTAINER c. SAP Docking Container The SAP Docking Container allows you to attach a control to any of the four edges of a screen as a resizable screen area. By using Object Oriented ALV. You can also detach it so that it becomes an independent modal dialog box. SAP Custom Container The SAP Custom Container allows you to display controls in an area defined on a normal screen using the Screen Painter. The first step in object oriented ALV is to create a container. There are five kinds of ALV Containers. In the object oriented ALV we have wrapper class to implement the object oriented functionality. Class: CL_GUI_DOCKING_CONTAINER 16 .ALV In ABAP SAMPLE CODE : Sam source code ple Introduction to Object Oriented ALV Instead of using standard function modules SAP also provides Classes for using ALV.

we need a custom container area on the screen. * This spit the container OB_CUSTOM into two CREATE OBJECT ob_split1 EXPORTING 17 . The cells are separated by a moveable splitter bar. Class: CL_GUI_SPLITTER_CONTAINER e. If we want more than one ALV displays we need to split the container. To create a custom container. STEP 2: SPLIT The Container. SAP Splitter Container The SAP Splitter Container allows you to display more than one control in a given area by dividing it into cells. SAP Easy Splitter Container The SAP Easy Splitter Container allows you to divide an area into two cells with a control in each.ALV In ABAP d. Create a custom control in the screen layout. * This will create a container CREATE OBJECT ob_custom EXPORTING container name = ’CONTAINER’.

CALL METHOD ob_grid1->set_table_for_first_display EXPORTING is layout = t_layout CHANGING it_outtab = T_MISC_OUTPUT1 IT_FIELDCATALOG = t_fieldcat. The commonly used fields of this type are: FIELDNAME: You use this field to assign a field name of your output table to a row of the field catalog. REPTEXT: Relevant only to fields with reference to the Data Dictionary. STEP 3: * Now Put a grid in each container CREATE OBJECT ob_grid1 EXPORTING i_parent = ob_split1->top_left_container. The sash_position says that the container will be split in the ratio specified. OUTPUTLEN: Determines the column width of the field: 18 . The internal table for field catalog is of type ‘LVC_T_FCAT’.ALV In ABAP parent = ob_custom orientation = cl_gui_easy_splitter_container=>orientation_vertical SASH_POSITION = 70. STEP 4: Make the list to be displayed. All settings that you make in this row refer to the corresponding column of the output table. by calling the method ‘set_table_for_first_display’. the ALV Grid Control copies the field label for the header of the corresponding data element into this field. CREATE OBJECT ob_grid2 EXPORTING i_parent = ob_split1->bottom_right_container. This will split the container vertically. CALL METHOD ob_grid2->set_table_for_first_display EXPORTING is layout = t_layout1 CHANGING it_outtab = T_EDID4_N IT_FIELDCATALOG = t_fieldcat1. For such fields.

you can leave the field set to its initial value. The field catalog can be filled manually as discussed in the ALV using function modules. you must specify the desired field output length.com 19 .sdn. the ALV Grid Control optimizes the column width. the list shows a striped pattern in the print preview and when it is printed. The most commonly used fields in this type are: ZEBRA: If this field is set. CWIDTH_OPT: If this field is set.sap. In this case. GRID_TITLE: Title between grid control and toolbar. For fields without reference to the DDIC. The internal table used for layouts should be of type ‘LVC_S_LAYO’.ALV In ABAP If the field has a reference to the Data Dictionary. the ALV adopts the output length of the relevant domain. Sample output of two grid displays in one screen using Object Oriented ALV: Reference: www. It can be populated semi automatically using “LVC_FIELDCATALOG_MERGE”. You can then see the column header and the contents of the cells of this column.

Sign up to vote on this title
UsefulNot useful