You are on page 1of 5

3/25/2021 Creating simple ALV report | FREE SAP ABAP TUTORIALS

FREE SAP ABAP TUTORIALS

for your SAP knowledge – for every ABAP Developer

1SEP2014

Creating simple ALV report

posted in ABAP ALV, ABAP Tutorials by vylykhang

OVERVIEW

ABAP List Viewer (ALV) is an integrated element of the ABAP Objects programming
environment allowing application developers to quickly implement the display of structured datasets or
report. With the ALV, we can use almost uniform programming techniques independent of the ALV tool
in order to display various lists, tables, or tree structures. The methods, parameters, or classes only vary
where tool-specific functions require a special procedure.

ALV provides several basic functions:

Sorting
Filtering
Performing Aggregations
Enable Layout
Output to Excel/HTML

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

https://sapforbeginner.wordpress.com/2014/09/01/creating-simple-alv-report/ 1/5
3/25/2021 Creating simple ALV report | FREE SAP ABAP TUTORIALS

REUSE_ALV_FIELDCATALOG_MERGE Create field catalog from dictionary structure or internal


table

EXAMPLE

Simple ALV display

REPORT z01_demo_alv_simple.

DATA: lt_sflight TYPE TABLE OF sflight.

SELECT * FROM sflightINTO TABLE lt_sflight.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’


EXPORTING
i_structure_name = ‘SFLIGHT’
TABLES
t_ou ab = lt_sflight.

RESULT

(h ps://sapforbeginner.files.wordpress.com/2014/09/screen-shot-2014-09-01-at-5-02-02-pm.png)

https://sapforbeginner.wordpress.com/2014/09/01/creating-simple-alv-report/ 2/5
3/25/2021 Creating simple ALV report | FREE SAP ABAP TUTORIALS

We can also use function REUSE_ALV_GRID_DISPLAY to create the same simple ALV report. It
displays the results in grid rather than as a preview. Parameters are same as
REUSE_ALV_LIST_DISPLAY.

Example creating ALV Report using GRID DISPLAY. [From SAPHub]

An ALV report (h p://www.saphub.com/abap-tutorial/what-is-abap-alv/) 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
(h p://www.saphub.com/abap-tutorial/what-is-an-abap-internal-table-and-how-to-create-it/).
Build Field Catalog – Add the columns into an internal that (h p://www.saphub.com/abap-
tutorial/what-is-an-abap-internal-table-and-how-to-create-it/) you want to display in the ALV output
list.
Pass the data table and field catalog table to ALV function module

https://sapforbeginner.wordpress.com/2014/09/01/creating-simple-alv-report/ 3/5
3/25/2021 Creating simple ALV report | FREE SAP ABAP TUTORIALS

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'. " Fieldname 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
EXCEPTIONS
program_error = 1
OTHERS = 2.

https://sapforbeginner.wordpress.com/2014/09/01/creating-simple-alv-report/ 4/5
3/25/2021 Creating simple ALV report | FREE SAP ABAP TUTORIALS

Output

(h p://www.saphub.com/wp-
content/uploads/2012/02/create-simple-abap-alv-1.png)

ALV, internal table  1 Comment

One thought on “Creating simple ALV report”

Pingback: Field Catalog in SAP ALV | FREE SAP ABAP TUTORIALS

Blog at WordPress.com. Do Not Sell My Personal Information

https://sapforbeginner.wordpress.com/2014/09/01/creating-simple-alv-report/ 5/5

You might also like