Appendix :A ABAP List Viewer (ALV

)

A

Appendix :B Contents
Overview..................................................................................................................... 2 What Is The ABAP List Viewer?...............................................................................2 ABAP List Viewer: Cost Versus Benefit Analysis...................................................3 Report Lists Without ABAP List Viewer .................................................................4 Report Lists With ABAP List Viewer .......................................................................5 Technical Notes....................................................................................................... 10 Sample Code Using ALV (Release 4.0B)...............................................................11 Review...................................................................................................................... 16 Where to Learn More...............................................................................................16

In this chapter you will learn:
  Why the ABAP List Viewer (ALV) is useful Some of the time-saving features of ALV, as well as its ability to enhance information display The differences between reports written with and without the ALV Technical information (sample code) to help you build reports with ALV “functionality”

Report Development Tools

1

Simple lists contain a number of non-hierarchical. user-defined columns.0 (and later) utilize the ABAP List Viewer.Appendix A: ABAP List Viewer (ALV) Review Overview If it becomes necessary to write ABAP code to create your reports. Note: At the time of press. Goals of ALV The primary goals of the ABAP List Viewer are to provide:  Users with a consistent. Developers can use the functionality of the ALV when creating new reports. thus saving time which might otherwise have been spent on report enhancement. and functional method of manipulating the data which appears on report lists. 2 Reporting Made Easy . limited technical support is available for the ABAP List Viewer. The ALV provides additional program code you can quickly add to any custom report for any SAP module. Sequential lists contain columns that consist of column headings and their subordinate rows.  ABAP developers with an efficient and consistent method of programming functions that are commonly needed or requested in reports. then consider using the ABAP List Viewer (ALV) to simplify your development. we believe that support limitations should not prevent you from taking advantage of the functionality offered by ALV. Using the ALV also provides a uniform user-interface and list format for ABAP reports. Programs created before Release 3. Available in the R/3 System since Release 3. Additionally. many older standard R/3 reports (and reporting tools) have been modified to include the ABAP List Viewer. The ABAP List Viewer enables both simple and sequential (hierarchical) report lists. However. What Is The ABAP List Viewer? The ALV is a set of function modules that are added to program code.1 can be enhanced with the ALV by adding links to the function modules. This standardization helps eliminate redundant functions. We recommend that developers should adopt ABAP List Viewer as a design principle in all report development activities that occur in your organization.1. user-friendly. The ABAP List Viewer can be used with any application component or module in the R/3 System. the ABAP List Viewer supports many of the standard R/3 reports. Many reports developed for Release 4.

and color Total Percentage of Time Taken to Complete 50% 1% 9% 0% 60% Although. ABAP Report Development Activity Without ALV Finding the right tables and table relationships that need to be included in order for the program to be written Providing “fancy” features. the use of ALV adds one more development activity (that is. subtotals. vertical lines. ABAP Report Development Activity With ALV Finding the right tables and table relationships that need to be included in order for the program to be written Preparing field catalog and sort sequence for ALV Providing “fancy” features. and interactivity Enhancing the look of the report with column headings. developers may want to consider the benefits gained versus the “extra time” taken to include ALV in report development. the development time spent on other activities is either eliminated or vastly reduced. and color Total Percentage of Time Taken to Complete 50% 30% 20% 100% SAP developed the ABAP List Viewer to help reduce the time and effort spent on some of the report development activities. Report Development Tools 3 . Note that an estimated 50% of report developers’ time is consumed by building “fancy” features and enhancing the look-and-feel of custom reports. subtotals. such as sorting. and interactivity Enhancing the look of the report with column headings. you could reduce the development time by an estimated 40% (see table below). vertical lines. By using the ALV in the programming of custom reports. preparation of the field catalog). such as sorting. The following table shows estimates of time expenditures in report development.Appendix A: ABAP List Viewer (ALV) Where to Learn More ABAP List Viewer: Cost Versus Benefit Analysis Before taking advantage of the features of ALV.

Appendix A: ABAP List Viewer (ALV) Review Report Lists Without ABAP List Viewer When a report is written. Often they are looking for the ability to: 4 Reporting Made Easy . Any additional functionality would have to be programmed. The output of a report created with just the WRITE statement is shown below: Function bar is blank No column headings List data is “dead. the interface between the data you see on the screen and the user’s eyes (the GUI) is limited and bland. For illustration purposes. In addition. Shown below is a sample report list where the programmer did not to use the ABAP List Viewer. the data in the list is “dead” which means that data listed cannot be used for any further data retrieval.” It is simply a so-called “data dump” A key point to note is that the function bar is blank. consider a report that was simply written (using the WRITE command) to the screen. It is essentially a “data-dump. In short.” Among other things. the report list (output) depends almost entirely on how the developer programmed the report. Report users routinely ask for additional features in their reports. there are no headings for the columns.

the manner in which this added functionality works may vary greatly. Report Lists With ABAP List Viewer When you insert the ALV code in your ABAP report program. the report list comes “alive. but another programmer may program it as 20 characters. the user is presented with a standard interface which. For example. With the ALV. includes:   Headers for the columns that appear on the list. for the most part. one programmer may decide to enable a single-click as sufficient user input to jump to a next level of information. one programmer may set the output of a field at 10 characters long.” Compare the ALV-enabled list shown on page A-6 with the list shown on the previous page. While some of these added functions are relatively easy to program. Similarly. these features need to be programmed into the list as added functionality to the output of the report. while another programmer requires a double-click. from the outset. Colors that correspond to indented key information  Buttons that appear on the function bar (some of whose functions will be introduced in the pages that follow) Report Development Tools 5 . Although the data is the same. the program has been changed to incorporate the ALV function modules.Appendix A: ABAP List Viewer (ALV) Where to Learn More Hint: These functions are all available in ALV  Sort  Resize rows  Double-click on one information element to jump to another information element  Perform basic calculations  Download “stylized” spreadsheets  Display several colors  Visually separate various pieces of information on the screen However.

Appendix A: ABAP List Viewer (ALV) Review A feature-rich function bar gives the user commonly requested functionality Function bar is blank Column headings make data easier to understand List data is “alive” As you review the additional functionality shown above. refer to the ALV documentation in the R/3 online documentation: R/3 Library → CA-Cross-Application Components → General Application Functions → ABAP List Viewer Guided Tour This guided tour shows possible ways a user could interact with an ALV-enabled report list. 6 Reporting Made Easy . remember that without the ALV each function would have to be programmed into the report. However. this appendix does not cover the full breadth of ALV functionality. Note: This appendix introduces you to some of the functions that the ALV makes possible. For more information.

2 1 3. With ALV’s added functionality the color of the selected column can be changed. 2. 3 4 Report Development Tools 7 . With the filter option. Select the column for Sales doc. 1. the user only wants to views sales documents that are between the numbers 1000 and 2000. In this instance. making it easy for the report user to know which column has been selected. 4.Appendix A: ABAP List Viewer (ALV) Where to Learn More In an ALV-enabled report list. a user can call up a desired subset of information on the output list. a user can select a particular column and execute a subsequent function. if desired. Set the filter for the sales documents to be viewed. Choose Copy to invoke the ALV to filter the list. Choose Filter.

we select Material Group. all fields appear. the columns that currently appear in the list are shown in the left section. select the row which lists the column you want to hide. If not all columns of the report are of interest to the user. a user can simply click the arrow buttons without having to exit and reexecute the report.Appendix A: ABAP List Viewer (ALV) Review 5. To return to the previous list. the unwanted columns can be hidden. To make one column disappear. To hide (or to view previously hidden columns). Hidden fields (if any) appear on the right section. 7. Then. This can be accomplished by setting the current variant to include only the desired columns. 8. In this example. 5 6 In the popup window. In this example. 7 8 8 Reporting Made Easy . 6. click the single rightarrow button to move the selected column (Material group) to the hidden fields section. The resulting filtered list is shown to the right. choose Display variant.

9 The “new” output list appears. For this change to take effect. The original list may be revisited by simply choosing the current variant. Report Development Tools 9 . 9. choose Copy.Appendix A: ABAP List Viewer (ALV) Where to Learn More The Material Group is now one of the hidden fields.

To include the ALV in a report. Build event catalogs. SAP delivers several function modules related to the ALV. it is necessary to include certain statements in the report’s program code. K_KKB_LIST_DISPLAY is still available but should no longer be used! Review the sample program on page 11 which shows the coding related to each of steps listed above. 4. Start ABAP List Viewer using SAP’s standard delivered function modules (see TechTalk below). In the standard R/3 System. and userfriendliness of the ALV. 2. Process call back events. the following basic steps must completed: 1. Select data into internal table. This section is intended for those who actually write the code for reports. 7. Use the following function modules with Release 4. 3. 10 Reporting Made Easy .txt) on the companion CD supplied with this guidebook series. You will find the source code (ZFIGALV. Declare the internal table to store selected data.Appendix A: ABAP List Viewer (ALV) Review Technical Notes In order for the reports to provide the consistency. 5. flexibility. 6. Note: The source code that appears on page 11 was used to create the sample ALV-enabled report list presented in this appendix.0: REUSE_ALV_LIST_DISPLAY (this is the primary function module) or other function modules that begin with the name REUSE_ALV*. Declare data areas for List Viewer. Build the field catalogs.

CHARG LIKE VBAP-CHARG. VBELN LIKE VBAP-VBELN. ARKTX LIKE VBAP-ARKTX. *******Declare Internal Table to Store Selected Data (End)**** *******Select Data into Internal Table (Begin) *************** SELECT VBELN POSNR MATNR MATKL KWMENG VRKME INTO CORRESPONDING FIELDS OF TABLE IVBAP FROM VBAP WHERE VBELN NE 0. POSNR LIKE VBAP-POSNR.Appendix A: ABAP List Viewer (ALV) Where to Learn More Sample Code Using ALV (Release 4. DATA: COL_POS TYPE I.0B) ************************************************************** REPORT ZFIGALV . *******Declare Data Areas for List Viewer (End)*************** *******Declare Internal Table to Store Selected Data (Begin)** DATA: BEGIN OF IVBAP OCCURS 0. ********Declare Data Areas for List Viewer (Begin)************ TYPE-POOLS: SLIS. SORTCAT_LN LIKE LINE OF SORTCAT. VRKME LIKE VBAP-VRKME. MATKL LIKE VBAP-MATKL. MATNR LIKE VBAP-MATNR. DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV. EVENTCAT TYPE SLIS_T_EVENT. KWMENG LIKE VBAP-KWMENG. EVENTCAT_LN LIKE LINE OF EVENTCAT. END OF IVBAP. Report Development Tools 11 . FIELDCAT_LN LIKE LINE OF FIELDCAT. SORTCAT TYPE SLIS_T_SORTINFO_ALV.

FIELDCAT_LN-REF_TABNAME = 'VBAP'. BUILD_SORTCAT2. FIELDCAT_LN-FIELDNAME = 'VBELN'. BUILD_FIELDCAT2. FORM BUILD_FIELDCAT2. FIELDCAT_LN-COL_POS = COL_POS. FIELDCAT_LN-QFIELDNAME = SPACE. *******Build Event Catalog (End)******************************* *******Start List Viewer (Begin)******************************* PERFORM START_LIST_VIEWER. 12 Reporting Made Easy . FIELDCAT_LN-KEY = 'X'.Appendix A: ABAP List Viewer (ALV) Review ******* Select Data into Internal Table (End) **************** ******* Build Field Catalogs (Begin)************************** PERFORM PERFORM PERFORM PERFORM PERFORM BUILD_FIELDCAT. FIELDCAT_LN-HOTSPOT = 'X'. BUILD_SORTCAT. FIELDCAT_LN-REF_TABNAME = 'VBAP'. FIELDCAT_LN-KEY = SPACE. ENDFORM. BUILD_FIELDCAT3. APPEND FIELDCAT_LN TO FIELDCAT. ADD 1 TO COL_POS. *******Build Field Catalogs (End)****************************** *******Build Event Catalog (Begin)***************************** PERFORM BUILD_EVENTCAT. *******Start List Viewer (End)********************************* *************************************************************** *************************************************************** *********FORM ROUTINES (Begin)********************************* FORM BUILD_FIELDCAT. FIELDCAT_LN-FIELDNAME = 'MATNR'. ADD 1 TO COL_POS. FIELDCAT_LN-DO_SUM = SPACE. FIELDCAT_LN-NO_OUT = SPACE.

SORTCAT_LN-UP = 'X'. FORM BUILD_SORTCAT. EVENTCAT_LN-FORM = 'PAGE_HEADER'. ENDFORM. APPEND SORTCAT_LN TO SORTCAT. APPEND FIELDCAT_LN TO FIELDCAT. ENDFORM. SORTCAT_LN-DOWN = 'X'. FORM BUILD_SORTCAT2. FIELDCAT_LN-REF_TABNAME = 'VBAP'. FIELDCAT_LN-NO_OUT = SPACE. ENDFORM. FIELDCAT_LN-QFIELDNAME = SPACE. SORTCAT_LN-FIELDNAME = 'MATNR'. SORTCAT_LN-FIELDNAME = 'VRKME'. SORTCAT_LN-SPOS = '1'. FIELDCAT_LN-QFIELDNAME = SPACE. FIELDCAT_LN-FIELDNAME = 'MATKL'. Report Development Tools 13 . ENDFORM. APPEND EVENTCAT_LN TO EVENTCAT. FIELDCAT_LN-HOTSPOT = SPACE. SORTCAT_LN-SUBTOT = 'X'. FIELDCAT_LN-NO_OUT = SPACE. FIELDCAT_LN-DO_SUM = 'X'.Appendix A: ABAP List Viewer (ALV) Where to Learn More FIELDCAT_LN-DO_SUM = SPACE. SORTCAT_LN-UP = SPACE. ADD 1 TO COL_POS. SORTCAT_LN-SUBTOT = SPACE. FIELDCAT_LN-COL_POS = COL_POS. APPEND SORTCAT_LN TO SORTCAT. FIELDCAT_LN-COL_POS = COL_POS. FIELDCAT_LN-KEY = SPACE. APPEND FIELDCAT_LN TO FIELDCAT. FORM BUILD_FIELDCAT3. EVENTCAT_LN-NAME = 'TOP_OF_PAGE'. FIELDCAT_LN-HOTSPOT = SPACE. FORM BUILD_EVENTCAT. SORTCAT_LN-DOWN = SPACE. SORTCAT_LN-SPOS = '2'.

PGM = SY-REPID. FORM START_LIST_VIEWER. ********Process Call Back Events (Begin)*************************** FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.Appendix A: ABAP List Viewer (ALV) Review ENDFORM. 14 Reporting Made Easy . DATA: PGM LIKE SY-REPID. ENDFORM. CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' I_CALLBACK_PROGRAM = PGM * i_callback_pf_status_set = ' ' I_CALLBACK_USER_COMMAND = 'USER_COMMAND' * I_STRUCTURE_NAME = * IS_LAYOUT = IT_FIELDCAT = FIELDCAT * IT_EXCLUDING = * IT_SPECIAL_GROUPS = IT_SORT = SORTCAT * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' I_SAVE = 'A' * IS_VARIANT = ' ' * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * 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 = IVBAP EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2.

CHECK SY-SUBRC = 0. CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. CASE SELFIELD-SEL_TAB_FIELD. CASE UCOMM. ********Process Call Back Events (End)****************************** ***********FORM ROUTINES (END)************************************** Report Development Tools 15 . WHEN '&IC1'. WHEN 'IVBAP-MATNR'. SET PARAMETER ID 'MAT' FIELD IVBAP-MATNR. ENDCASE.Appendix A: ABAP List Viewer (ALV) Where to Learn More READ TABLE IVBAP INDEX SELFIELD-TABINDEX. ENDFORM. ENDCASE. WHEN 'IVBAP-VBELN'. SET PARAMETER ID 'AUN' FIELD IVBAP-VBELN.

In the HTML help documentation. Declare the internal table to store selected data.1. and was first made available with Release 3. Start the ABAP List Viewer using SAP’s standard delivered function modules. 7. Select data into internal table. 2. The ALV is a set of function modules added to program code. 3. the following basic steps must completed:  1. Build event catalogs. Build field catalogs. go to: R/3 System Library → CA-Cross-Application Components → General Application Functions → ABAP List Viewer 16 Reporting Made Easy .Appendix A: ABAP List Viewer (ALV) Review Review  The ABAP List Viewer (ALV) functionality provided within ABAP can enhance reports in the R/3 System. Declare data areas for List Viewer. 5.  The ALV provides the following features:  Sorting  Resizing of rows  Double-clicking on one information element to jump to another information element  Performing basic calculations  Downloading of stylized spreadsheets  Displaying several colors  Visually separating various pieces of information on the screen To include the ALV in a report. refer to the R/3 Library (online documentation). Process call back events. 4. Where to Learn More For more information.  Using the ALV provides a uniform user-interface and list format for ABAP reports. 6. Programs created before this release can be enhanced with the ALV by adding links to the function modules.  Using the ALV enhances the functionality provided with reports while decreasing the development time by roughly 40%. This standardization helps eliminate redundant functions.

Appendix A: ABAP List Viewer (ALV) Where to Learn More Report Development Tools 17 .