How does this relate to Duet?
Since ALV Grid is out for quite a while, you might wonder why I start blogging about it now. The reason is that with Duet for Microsoft Office and SAP you can execute ABAP reports within Microsoft Outlook and get the ALV-based result delivered as email. The table data is embedded in the mail and can be opened in Microsoft Excel with a single click.
So what is ALV all about?
ALV stands for SAP List Viewer. If you didn’t get used to the SAP abbreviation craziness yet, you might wonder about the A. That’s because before R/3 release 4.6C, it was called ABAP List Viewer. ALV is a technology for displaying lists containing predefined functions such as sorting or filtering and allowing individual responses to user actions such as double clicking a table item.
When you create lists through WRITE statements, it’s the ABAP list processor’s task to store, display and manage the lists. While the program is executed, the lists are stored on the application server and displayed on a special container screen with the help of the list processor. For those WRITE-based lists, no structural information is passed to the ABAP list processor, but they appear as an unstructured character stream to the front end.
In contrast, the ALV uses control technology for displaying lists. Controls are binary reusable software components installed as part of SAP GUI. As a consequence, there is no need to access the application server in order to – for example – move columns of a currently displayed table. By using controls, functionality and load is moved from the application server (back end) to each client’s SAP GUI (front end). Additionally, the front end is now aware of the structure behind the presented information, so the data can sorted or filtered or sums can be calculated.
You can find a high-level overview of SAP List Viewer (ALV) Grid Control (BC-SRV-ALV) and its features at help.sap.com. Now let’s drill down to the details.
How can I create ALV reports?
To facilitate the development of ALV-based tables, SAP provides a variety of function modules. For a complete list go to SE37, enter REUSE_ALV* and press F4. I will focus on REUSE_ALV_LIST_DISPLAY and REUSE_ALV_GRID_DISPLAY in the following. Function module REUSE_ALV_LIST_DISPLAY presents an internal table as a simple list. There is no Dynpro, container or GUI status necessary because an own status is created by default. The data is presented in as ALV Classic design in full screen mode as shown below.
As part of the enjoySAP initiative (Long long time ago, do you still remember?), the ALV was equipped with a modern design. REUSE_ALV_GRID_DISPLAY based on the class CL_GUI_ALV_GRID presents a more enjoyable user interface. To simplify the migration from ALV Classic, this function module has the same interface as REUSE_ALV_LIST_DISPLAY. Ideally, developers only need to replace LIST with GRID in the function module call. This backward compatibility is also used to switch back to LIST when system performance requires it or for printing and printing preview purposes.
Both function modules expect at least two parameters: the data itself and a description how the data should be displayed. This description can be provided by the Data Dictionary (DDIC) structure or through a field catalog.
To create an ALV list of flight data, just the following lines of code are necessary:
DATA lt_sflight TYPE TABLE OF sflight. SELECT * FROM sflight INTO TABLE lt_sflight. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_structure_name = 'SFLIGHT' TABLES t_outtab = lt_sflight.
If the structure of the output table T_OUTTAB corresponds to the structure I_STRUCTURE_NAME stored in the Data Dictionary, a field catalog is created automatically. This leads to all fields of this DDIC structure being displayed. In case this is not the desired behavior, you can define a field catalog manually.
With the help of a field catalog, you can decide which fields of a structure are shown, modify their properties and manually add field descriptions and formatting options. A field catalog is an internal table of the type SLIS_T_FIELDCAT_ALV. Each line of this table corresponds to a column of the data table. Since the function module REUSE_ALV_FIELDCATALOG_MERGE creates a field catalog of a given DDIC structure, the following lines of code provide the same result as those above.
TYPE-POOLS slis. DATA lt_fieldcat TYPE slis_t_fieldcat_alv. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'SFLIGHT' CHANGING ct_fieldcat = lt_fieldcat. DATA lt_sflight TYPE TABLE OF sflight. SELECT * FROM sflight INTO TABLE lt_sflight. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING it_fieldcat = lt_fieldcat TABLES t_outtab = lt_sflight.
To modify existing field descriptions, you loop through the field catalog and change the corresponding attributes. To add a column description, just append a new line to the field catalog table. The following fields are obligatory:
If column is part of a DDIC structure:
FIELDNAME Name of the field in the internal output table
REF_TABNAME Name of the DDIC reference structure
All other values are derived from the referenced field.
If column is not part of a DDIC structure:
FIELDNAME Name of the field in the internal output table
DATATYPE Data type of the field in the internal output table
OUTPUTLEN Column width
SELTEXT_L Long text
SELTEXT_M Medium text
SELTEXT_S Short text
SELTEXT_* represents the text used as column heading and tool tip depending on the actual column width.
For a detailed documentation of the various parameters and settings, view REUSE_ALV_GRID_DISPLAY in SE37 and click on “Function Module Documentation” button in the top bar on the very right.
Which tools can support me in creating ALV reports?
As for any function module, you can use Edit -> Pattern (Ctrl+F6) in ABAP Editor to have the call code generated. Optional parameters are commented.
The SAP flight model contains some ALV sample reports. In SE38, enter BALV* and press F4 to get a selection of ALV reports. For the Duet-based screenshots I used report BALVEX02.
If you decide to build a report from scratch, the Reduce development costs with ABAP Report Wizard (Community Day Launch in Vegas!) could be helpful. Its output will also be an ALV grid. To generate ALV call code for an existing report quickly, there are free code generators available. If you have an existing report with the output data in an internal table already, you can use these wizards to generate the ALV coding: ALV Grid Tool or ALV Robot (Disclaimer: SAP is not responsible for the content of external links. Use at your own judgement and risk.)
Once you migrated your WRITE-based report to ALV (or built an ALV report from scratch), it is ready to be used with Duet. So in the end, I will present that Excel screen I implicitly promised in my introduction.