7 ALV Reports
7 ALV Reports
7 ALV Reports
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
Because of the above functions, ALV substantially decreases the report development time. ALV takes care of
rendering the list and we can concentrate only on the data retrieval part.
Some of the function modules used to create ALV reports are listed below.
FUNCTION MODULE
DESCRIPTION
REUSE_ALV_LIST_DISPLAY
REUSE_ALV_GRID_DISPLAY
REUSE_ALV_COMMENTARY_WRITE
REUSE_ALV_VARIANT_F4
REUSE_ALV_VARIANT_EXISTENCE
REUSE_ALV_FIELDCATALOG_MERGE
= it_spfli.
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.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
= 'CARRID'.
wa_fieldcat-seltext_m
= 'Airline'.
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'PASSNAME'.
wa_fieldcat-seltext_m
= 'Passenger Name'.
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
Output
= 2.
We want to display all the fields from the DDIC structure but want to modify certain attributes like
descriptions etc.
We want to display most of the fields i.e. we want to hide certain fields.
Add new fields.
To generate a field catalog semi-automatically:
Read the rows you want to change, and adapt the fields accordingly. If your output table contains more
fields than are stored in the Data Dictionary, you must append one row for each new field to the field catalog.
Example Program
TYPE-POOLS: slis.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
= 'STATUS'.
wa_fieldcat-seltext_m
= 'Status'.
= 'SBOOK'
CHANGING
ct_fieldcat
= it_fieldcat
EXCEPTIONS
inconsistent_interface
= 1
program_error
= 2
OTHERS
= 3.
*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
Output
= 2.
Status column is added to the field catalog along all the fields of structure SBOOK.
2.
Pass
the
TOP-OF-EVENT
subroutine
name
and
callback
program
name
to
Display the ALV header by passing the ALV header table built in
Data Decalaration
*----------------------------------------------------------------------*
DATA: it_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPE sy-repid.
DATA: it_listheader TYPE slis_t_listheader,
wa_listheader TYPE slis_listheader.
*----------------------------------------------------------------------*
*
START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
PERFORM build_alv_header.
= g_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name
= 'SPFLI'
TABLES
t_outtab
= it_spfli.
*&---------------------------------------------------------------------*
*&
Form
BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
FORM build_alv_header .
= 'H'.
sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
ENDFORM.
" BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*&
Form
top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
ENDFORM.
Output
"top_of_page
First upload the logo that you want to display in ABAP ALV header.
2.
3.
Pass
the
TOP-OF-EVENT
subroutine
name
and
callback
program
name
to
Display the ALV header and logo by passing the ALV header table built in step two and logo that you
uploaded
subroutine.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*
Data Decalaration
*----------------------------------------------------------------------*
DATA: it_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPE sy-repid.
DATA: it_listheader TYPE slis_t_listheader,
wa_listheader TYPE slis_listheader.
*----------------------------------------------------------------------*
*
START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
SELECT * FROM spfli INTO TABLE it_spfli.
PERFORM build_alv_header.
= g_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name
= 'SPFLI'
TABLES
t_outtab
= it_spfli.
*&---------------------------------------------------------------------*
*&
Form
BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
FORM build_alv_header .
*
= 'H'.
sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
:' .
" BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*&
Form
top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_listheader
i_logo
= 'MYLOGO'.
ENDFORM.
"top_of_page
Output
Build field catalog and set the field DO_SUM of field catalog to X for the field for which you want
calculate the totals.
2.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_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'.
wa_fieldcat-seltext_m
= 'Airline'.
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'PASSNAME'.
wa_fieldcat-seltext_m
= 'Passenger Name'.
= 'LOCCURAM'.
wa_fieldcat-seltext_m
= 'Price'.
= 'X'.
= 'LOCCURKEY'.
wa_fieldcat-seltext_m
= 'Currency'.
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
Output
= 2.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
TYPE slis_fieldcat_alv,
it_sort
TYPE slis_t_sortinfo_alv,
wa_sort
TYPE slis_sortinfo_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'.
wa_fieldcat-seltext_m
= 'Airline'.
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'PASSNAME'.
wa_fieldcat-seltext_m
= 'Passenger Name'.
= 'LOCCURAM'.
wa_fieldcat-seltext_m
= 'Price'.
wa_fieldcat-do_sum
= 'X'.
= 'LOCCURKEY'.
wa_fieldcat-seltext_m
= 'Currency'.
= 1.
wa_sort-fieldname = 'CARRID'.
wa_sort-up
= 'X'.
wa_sort-subtot
= 'X'.
= it_fieldcat
it_sort
= it_sort
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
= 2.
Output
If you want to calculate subtotals for more fields, just add a record in sort field catalog for each field.
*Build sort catalog
wa_sort-spos
= 1.
wa_sort-fieldname = 'CARRID'.
wa_sort-up
= 'X'.
wa_sort-subtot
= 'X'.
= 2.
wa_sort-fieldname = 'CONNID'.
wa_sort-up
= 'X'.
wa_sort-subtot
= 'X'.
2.
Build field catalog and fill the excluding table with function codes of icons that you want to disable.
&ILT& is the function code for Filter Icon.
3.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
TYPE slis_fieldcat_alv.
slis_t_extab,
slis_extab.
TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
*Fetch data from the database
SELECT * FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname
= 'CARRID'.
wa_fieldcat-seltext_m
= 'Airline'.
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'PASSNAME'.
wa_fieldcat-seltext_m
= 'Passenger Name'.
wa_excluding-fcode = '&ILT'.
= it_fieldcat
it_excluding
= it_excluding
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
2.
3.
To get the currency wise totals of price, fill the CFIELDNAME field of field catalog with the currency
column name and set do_sum to X.
4.
To get the quantity wise totals of luggage, fill the QFIELDNAME field of field catalog with the weight unit
column name and set do_sum to X.
5.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
DATA: g_repid
TYPE slis_fieldcat_alv.
TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
*Fetch data from the database
SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname
= 'CARRID'.
wa_fieldcat-seltext_m
= 'Airline'.
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'FORCURAM'.
wa_fieldcat-seltext_m
= 'Price'.
wa_fieldcat-do_sum
= 'X'.
wa_fieldcat-cfieldname = 'FORCURKEY'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'FORCURKEY'.
wa_fieldcat-seltext_m
= 'Currency'.
= 'LUGGWEIGHT'.
wa_fieldcat-seltext_m
= 'Weight'.
wa_fieldcat-do_sum
= 'X'.
wa_fieldcat-qfieldname = 'WUNIT'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'WUNIT'.
wa_fieldcat-seltext_m
= 'Unit'.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
Output
1.
Add a column to the internal table to hold the traffic lights value(i.e. 1 for RED, 2 for YELLOW and 3 for
GREEN).
2.
3.
4.
To display traffic lights in the ALV, fill the lights field name in the LIGHTS_FIELDNAME of ALV layout.
5.
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_sbook.
INCLUDE STRUCTURE sbook.
TYPES: icon TYPE c,
END OF ty_sbook.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
DATA: wa_sbook
TYPE ty_sbook.
DATA: it_fieldcat
TYPE slis_t_fieldcat_alv,
wa_fieldcat
TYPE slis_fieldcat_alv.
DATA: is_layout
TYPE slis_layout_alv.
DATA: g_repid
TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
*Fetch data from the database
SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.
*Assign different traffic lights to each row based on condition
LOOP AT it_sbook INTO wa_sbook.
IF wa_sbook-luggweight LE 0.
wa_sbook-icon = 1.
ELSE.
wa_sbook-icon = 3.
ENDIF.
MODIFY it_sbook FROM wa_sbook TRANSPORTING icon.
CLEAR: wa_sbook.
ENDLOOP.
*Build field catalog
wa_fieldcat-fieldname
= 'CARRID'.
wa_fieldcat-seltext_m
= 'Airline'.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname
= 'CONNID'.
wa_fieldcat-seltext_m
= 'Con. No.'.
= 'FLDATE'.
wa_fieldcat-seltext_m
= 'Date'.
= 'BOOKID'.
wa_fieldcat-seltext_m
= 'Book. ID'.
= 'FORCURAM'.
wa_fieldcat-seltext_m
= 'Price'.
= 'FORCURKEY'.
wa_fieldcat-seltext_m
= 'Currency'.
= 'LUGGWEIGHT'.
wa_fieldcat-seltext_m
= 'Weight'.
= 'WUNIT'.
wa_fieldcat-seltext_m
= 'Unit'.
= is_layout
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
Output
program_error
= 1
OTHERS
= 2.