Alv Reports

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

ALV REPORTS

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


– 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

• ALV substantially decreases the report development time

• ALV takes care of rendering the list and we can concentrate only on the data
retrieval part.
Function modules used to create ALV reports
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 – Step by Step
• 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
Simple ALV report.

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.

1
Field catalog
• The field catalog is a table which contains information
on the fields to be displayed on the ALV output.
• First we need to build a field catalog before displaying
any output in the ALV
• We have the following three ways to build a field
catalog.
1. Automatically through a Data Dictionary structure.
2. Manually in ABAP program.
3. Semi-automatically by combining the above two
procedures.

2
• The third option is used in the following cases
– 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
– Declare an internal table of type SLIS_T_FIELDCAT_ALV.
– Call function module REUSE_ALV_FIELDCATALOG_MERGE and pass the
DDIC structure of the output table and the internal table for the field
catalog. The function module generates the field catalog and fills the
internal table accordingly.
– 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.
3
Display Header in ABAP ALV Grid

• Build the ALV header table.


• Pass the TOP-OF-EVENT subroutine name and
callback program name to
I_CALLBACK_TOP_OF_PAGE and
I_CALLBACK_PROGRAM parameters of
REUSE_ALV_GRID_DISPLAY function module.
• Display the ALV header by passing the ALV header
table built in   step one to function module
‘REUSE_ALV_COMMENTARY_WRITE’ inside TOP-OF-
EVENT subroutine.
4
Display Logo in ABAP ALV Header

• First upload the logo that you want to display in


ABAP ALV header.
• Build the ALV header table.
• Pass the TOP-OF-EVENT subroutine name and callback
program name to I_CALLBACK_TOP_OF_PAGE and
I_CALLBACK_PROGRAM parameters of
REUSE_ALV_GRID_DISPLAY function module.
• Display the ALV header and logo by passing the ALV header
table built in   step two and logo that you uploaded  in step
one to function module ‘REUSE_ALV_COMMENTARY_WRITE’
inside TOP-OF-EVENT subroutine
5
Logo should be uploaded into application server using transaction
'OAER‘

• Go to Transaction OAER,
• Give Class Name as PICTURES
• Class type as OT
• Object Key as the name of the Object u want to
specify
• Upon execution you would be prompted to give
the file path details. Just upload which ever logo u
want to display
• Now you can use the same name in your ALV FM
form top-of-page1.
wa-typ = 'S'.
data: header type slis_t_listheader, concatenate text-h01 sy-repid into wa-info
wa type slis_listheader. separated by space.
append wa to header.
* TITLE AREA
wa-typ = 'S'. ********" LOGO
wa-info = text-h04.
append wa to header. call function
'REUSE_ALV_COMMENTARY_WRITE'
wa-typ = 'S'.
write sy-datum to wa-info mm/dd/yyyy. exporting

concatenate text-h03 wa-info into wa-info it_list_commentary = header


separated by space.
append wa to header. i_logo = 'ENJOYSAP_LOGO'.

wa-typ = 'S'. *********" LOGO


concatenate text-h02 sy-uname into wa-info
separated by space. endform.
append wa to header.
Display Subtotal and Total in ABAP ALV Grid

• Build field catalog and set the field DO_SUM of field catalog to
‘X’ for the field for which you want calculate the totals.
• Pass field catalog to function module 6
‘REUSE_ALV_GRID_DISPLAY’.
• To calculate subtotal in ALV, build sort catalog and set the field
SUBTOT of sort catalog to ‘X’

wa_fieldcat-fieldname = 'PASSNAME'.
7
wa_fieldcat-seltext_m = 'Passenger Name'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'LOCCURAM'.
wa_fieldcat-seltext_m = 'Price'.
*Calculate Total for Price
8
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
Currency wise and Quantity wise Totals in SAP ALV
wa_fieldcat-fieldname = 'FORCURAM'.
• Fetch data from database table. wa_fieldcat-seltext_m = 'Price'.
• Build field catalog. wa_fieldcat-do_sum = 'X'.
wa_fieldcat-cfieldname = 'FORCURKEY'.
• To get the currency wise totals of APPEND wa_fieldcat TO it_fieldcat.
price, fill the CFIELDNAME field of
field catalog with the currency CLEAR wa_fieldcat.
column name and set do_sum to ‘X’. wa_fieldcat-fieldname = 'FORCURKEY'.
wa_fieldcat-seltext_m = 'Currency'.
• To get the quantity wise totals of APPEND wa_fieldcat TO it_fieldcat.
luggage, fill the QFIELDNAME field of CLEAR wa_fieldcat.
field catalog with the weight unit wa_fieldcat-fieldname = 'LUGGWEIGHT'.
wa_fieldcat-seltext_m = 'Weight'.
column name and set do_sum to ‘X’. wa_fieldcat-do_sum = 'X'.
• Pass field catalog to function module wa_fieldcat-qfieldname = 'WUNIT'.
‘REUSE_ALV_GRID_DISPLAY’. APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'WUNIT'.
wa_fieldcat-seltext_m = 'Unit'.
8 APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
Display Traffic Lights in SAP ALV

• 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).
• Fetch data from database table and build field catalog.
• Assign different traffic lights to each row based on
condition.
• To display traffic lights in the ALV, fill the lights field
name in the LIGHTS_FIELDNAME of ALV layout.
• Pass field catalog to function module
‘REUSE_ALV_GRID_DISPLAY’ 9
ALV Tree Control

You might also like