SAP ALV:
ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function modules provided by SAP.
ALV provides a lot of inbuilt functions to our reports and some of the functions are listed below.
- Sorting of records
- Filtering of records
- Totals and Sub-totals
- Download the report output to Excel/HTML
- Changing the order of the columns in the report
- Hide the unwanted columns from the report
Some of the function modules used to create ALV reports are listed below.
FUNCTION MODULE | DESCRIPTION |
---|---|
REUSE_ALV_LIST_DISPLAY | Display an ALV list |
REUSE_ALV_GRID_DISPLAY | Display an ALV grid |
REUSE_ALV_COMMENTARY_WRITE | Output List header information |
REUSE_ALV_VARIANT_F4 | Display variant selection dialog box |
REUSE_ALV_VARIANT_EXISTENCE | Checks whether a variant exists |
REUSE_ALV_FIELDCATALOG_MERGE | Create field catalog from dictionary structure or internal table |
Simple ALV report.
Example:
DATA: it_spfli TYPE TABLE OF spfli.
SELECT * FROM spfli INTO TABLE it_spfli.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_structure_name =
'SPFLI'
TABLES
t_outtab = it_spfli.
An ALV report is
created using the standard function modules provided by SAP.
An ALV report can be created using the following steps.
- Include SLIS type pool – SLIS type pool contains all the data types required by ALV function modules.
- Data retrieval – Code the logic to fetch the data from database table into an Internal Table.
- Build Field Catalog – Add the columns into an internal that you want to display in the ALV output list.
- Pass the data table and field catalog table to ALV function module
TYPE-POOLS: slis. "
SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
TYPE TABLE OF sbook.
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Fetch data from the database
SELECT * FROM sbook
INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname =
'CARRID'. " Field name in the data
table
wa_fieldcat-seltext_m =
'Airline'. " Column description in
the output
APPEND wa_fieldcat
TO it_fieldcat.
wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-seltext_m = 'Con.
No.'.
APPEND wa_fieldcat
TO it_fieldcat.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-seltext_m = 'Date'.
APPEND wa_fieldcat
TO it_fieldcat.
wa_fieldcat-fieldname = 'BOOKID'.
wa_fieldcat-seltext_m = 'Book.
ID'.
APPEND wa_fieldcat
TO it_fieldcat.
wa_fieldcat-fieldname =
'PASSNAME'.
wa_fieldcat-seltext_m =
'Passenger Name'.
APPEND wa_fieldcat
TO it_fieldcat.
*Pass data and field catalog to ALV function module to
display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_sbook
Output: