You are on page 1of 53

ABAP Training

ALV (Abap List Viewer)


ABAP Training ALV 2
ALV
ALV (Abap List Viewer) is a grid control, used for displaying
lists. The tool provides common list operations as generic
functions and enhanced by user-defined options.
The grid control itself consists of a toolbar, a title and the
output table displayed in a grid control. The user has control
over the look of the grid (to certain degree) by the use of
layout variants.
ABAP Training ALV 3
Functions Provided by ALV Grid Control
Display non-hierarchical lists consistently with a modern design
Use typical list functions - such as sorting and filtering without extra
programming effort
Adapt predefined list functions and their enhancements
Program responses to user actions (such as double-clicking a line)
individually
ABAP Training ALV 4
Example of Simple ALV
ABAP Training ALV 5
Sort
Sort Button in ALV
ABAP Training ALV 6
Filter
Filter Button in ALV
ABAP Training ALV 7
Filter Criteria
ABAP Training ALV 8
Using ALV, we can have three types of reports:
1. Simple Report
2. Block Report
3. Hierarchical Sequential Report
Types of ALV Reports
ABAP Training ALV 9
Two Types of Information for Displaying
Data in ALV Grid
An internal table with the data.
A description of the structure of this data that is declared to the ALV
grid control through the field catalog or through the corresponding
structure of the Data Dictionary.
Two ways to list data in ALV grid:
1. CALL METHOD
grid->set_table_for_first_display
2. CALL FUNCTION REUSE_ALV_LIST_DISPLAY
ABAP Training ALV 10
SAP Custom Container, Field Catalog,
Layout Structure
SAP custom container
The SAP custom container allows you to display controls in an area
defined on a normal screen using the screen painter.
Field catalog
The field catalog is a table that contains information on the fields to be
displayed. For example, the ALV uses this table to identify the type of a
field.
Layout structure
The layout structure is of type LVC_S_LAYO . it contains fields for
settinig graphical properties of the grid control, displaying exceptions,
calculating totals and enabling specific interaction options.
ABAP Training ALV 11
Method 1: CALL METHOD
Grid -> Set_table_for_first_display
You can use method set_table_for_first_display to pass the list data, the
field catalog, and any additional information to the ALV Grid Control
instance.
To pass the list data to be displayed, you use parameter it_outtab.
You pass the name of the row structure of the data table using
parameter i_structure_name. The proxy object then generates the field
catalog automatically. If you want to pass a field catalog that was
generated manually or semi-automatically, you must additionally use
parameter it_fieldcatalog..
You use parameters is_variant and i_save to control the use of display
variants. Using parameter i_default, you can determine that a display
variants should be loaded as default variant. This is the default setting of
the parameter.
ABAP Training ALV 12
Method 1: CALL METHOD
Grid -> Set_table_for_first_display
Parameters is_layout, is_print, it_special_groups and
it_toolbar_excluding allow you to pass your settings for the
control layout and the print list, as well as the names of the
field groups and the names of the functions to be disabled in
the toolbar.
Using parameters it_filter and it_sort, you can pass initial
filter and sort criteria to your proxy object.
The interface parameters use the following name
conventions: i_ = single field, is_ = structure, it_ = internal
table.
For details on the method and the interface parameters, see
the online documentation.
ABAP Training ALV 13
Method 1: CALL METHOD
Grid -> Set_table_for_first_display
1) declare reference variables for the ALV grid control and the container.
DATA: grid TYPE REF TO cl_gui_alv_grid,
G_custom_container TYPE REF TO cl_gui_custom_container,
Gt_sflight TYPE TABLE OF sflight. (Output table)
2) the SAP custom container allows you to display controls in an area
defined on a normal screen using the screen painter.
Class: CL_GUI_CUSTOM_CONTAINER
ABAP Training ALV 14
Method 1 Contd...
3) in the PBO module of the screen, you must now instantiate the container
control and the ALV grid control. By doing this, you create a link
between the container control and the screen, using the container
created in the screen painter.
CREATE OBJ ECT g_custom_container
Exporting
Container_name = 'ccontainer'. (As
declared on screen)
Create object grid1
Exporting
I_PARENT = g_custom_container.
ABAP Training ALV 15
Method 1 Contd...
4) pass the output table and the structure data to the ALV grid control.
CALL METHOD grid->set_table_for_first_display
Exporting i_structure_name = 'sflight'
CHANGING IT_OUTTAB = gt_sflight.
In this case, the structure data is provided through the data dictionary. The
ALV grid control gets the field information from table SFLIGHT and
displays all fields of the table. GT_SFLIGHT is the output table.
ABAP Training ALV 16
Steps Required
ABAP Training ALV 17
More About Fieldcatalogs
How to generate field catalog ?
Basically, we need a field catalog for each list that is displayed using the
ALV grid control. We have several options of generating a field catalog:
1. Automatically through a data dictionary structure
2. Manually in your ABAP program
3. Semi-automatically by combining the above two procedures.
ABAP Training ALV 18
1.Automatically Through a Data
Dictionary Structure
ABAP Training ALV 19
1.Automatically Through a Data
Dictionary Structure Contd....
Purpose :
If the structure of our output table corresponds to a structure stored in
the data dictionary (DDIC), the ALV grid control can use this information
to generate the field catalog automatically
Process :
Pass the structure in method set_table_for_first_display with parameter
I_STRUCTURE_NAME to the control created.
ABAP Training ALV 20
2. Manually in Your ABAP Program
ABAP Training ALV 21
2. Manually in Your ABAP Program Contd.
PURPOSE :
it may be the case that the data you want to display is not at all or only
partially represented by a structure in the data dictionary. Then you
must use the fields of the field catalog to describe the structure of the
output table.
PROCESS :
the field catalog is defined in the data dictionary through table type
LVC_T_FCAT . each row of the field catalog table explains a field in your
output table.
ABAP Training ALV 22
2. Manually in Your ABAP Program Contd.
Depending on whether a reference structure exists in the DDIC or not, you
must at least fill the following fields of the field catalog structure for
each field:
Output table fields with DDIC reference : FIELDNAME
REF_TABNAME
ref_TABNAMEOutput table fields without DDIC reference :
FIELDNAME
INTTYPE
OUTPUTLEN
COLTEXT
ABAP Training ALV 23
3. Semi-automatically by Combining the
Two
When generating the field catalog semi-automatically, you combine
structure information of the data dictionary with your own structure
information.
Purpose :
The output display can be manipulated in several ways for example -
To display a data dictionary table without displaying all possible columns
initially (using field NO_OUT of the field catalog).
To display additional columns containing icons or other information.
To change the output length of a column.(Field OUTPUTLEN)
ABAP Training ALV 24
3. Semi-automatically by Combining the
Two Contd..
Process:
Declare an internal table of type LVC_T_FCAT .
Call function module LVC_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. Loop the internal table remove unwanted types
Pass the field catalog to the method grid-
>set_table_for_first_display.
ABAP Training ALV 25
Output
Table
Internal
Table
SELECT *
FROM table
Data
a
1
b
1
c
1
a
2
b
2
c
2
a
3
b
3
c
3
Screen
Data Display on the Control
CALL METHODE
grid->SET_TABLE_FOR_FIRST_DISPLAY
Instantiation and Screen
Integration
CREATE OBJECT g_docking_container
EXPORTING extension = .
CREATE OBJECT grid1
EXPORTING
i_parents = g_docking_container
Declaration of
Reference Variables
DATA grid1 TYPE REF TO
CL_GUI_ALV_GRID,
g_docking_container TYPE REF TO
CL_GUI_DOCKING_CONTAINER.
Data
Description
Field Catalog
A Type
A
. . .
B Type
B
. . .
C
Type
C . . .
GRID
(Linked to
Screen through
Container)
I ntegration of ALV Grid Controls
ABAP Training ALV 26
METHOD 2 : CALL FUNCTION
REUSE_ALV_LIST_DISPLAY
1. Using type group SLIS : create field catalog and other necessary internal
tables.
2. Explain field description to ALV through field
Catalog.
3. Set messages for header and insert into GT_TOP_OF_PAGE
4. Call function 'reuse_ALV_list_display'
And pass field catalog and output internal table
ABAP Training ALV 27
Simple Report
Simple report
The important function modules are:
Reuse_alv_list_display
Reuse_alv_fieldcatalog_merge
Reuse_alv_events_get
Reuse_alv_commentary_write
Reuse_alv_grid_display
ABAP Training ALV 28
Simple Report CONTD.
A. REUSE_ALV_LIST_DISPLAY: this is the function module which prints the
data.
The important parameters are:
1. Export:
A. I_callback_program : report id
B. I_callback_pf_status_set : routine where a user can set his own pf
status or change the functionality of the
existing pf-status.
C. I_callback_user_command : routine where the function codes are
handled.
ABAP Training ALV 29
Simple Report Contd...
D. I_structure name : name of the dictionary table
E. Is_layout : structure to set the layout of the report
F. It_fieldcat : internal table with the list of all fields and their
Attributes which are to be printed (this
table can be populated automatically by the
function module
REUSE_ALV_FIELDCATALOG_MERGE)
G. It_events : internal table with a list of all possible events of
ALV and their corresponding routine names.
2. Tables:
A. T_outtab : internal table with the data to be output
ABAP Training ALV 30
Simple Report Contd...
B. Reuse_ALV_fieldcatalog_merge:
This function module is used to populate a fieldcatalog which is essential
to display the data in ALV. If the output data is from a single dictionary
table and all the columns are selected, then we need not exclusively
create the field catalog. Its enough to mention the table name as a
parameter(i_structure_name) in the REUSE_ALV_LIST_DISPLAY. But in
other cases we need to create it.
ABAP Training ALV 31
Simple Report Contd...
The important parameters are:
1. Export:
A. I_program_name : report id
B. I_internal_tabname : the internal output table
C. I_inclname : include or the report name where all the
dynamic Forms are handled.
2. Changing
Ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV
Which is declared in the type pool SLIS.
ABAP Training ALV 32
Simple Report Contd...
C . reuse_ALV_events_get: returns table of possible events for a a list
type
Import:
Et_events : the event table is returned with all possible
CALLBACK events for the specified list type
(Column NAME). For events to be processed by
The callback, their FORM field must be filled. If
The field is initialized, the event is ignored. The
Entry can be read from the event table, the field
FORM filled and the entry modified using
Constants from the type pool SLIS.
ABAP Training ALV 33
Simple Report Contd...
2. Export:
I_list_type:
0 = simple list
1 = hierarchical-sequential list
2 = simple block list
3 = hierarchical-sequential block list
ABAP Training ALV 34
Simple Report Contd...
D. REUSE_ALV_COMMENTARY_WRITE : this is used in the top-of-page
event to print the headings and other comments for the list.
1. It_list_commentary : internal table with the headings of the type
slis_t_listheader.
This internal table has three fields:
Typ : H - header, S - selection, A - action
Key : only when typ is S.
Info : the text to be printed
ABAP Training ALV 35
Simple Report Contd...
E. REUSE_ALV_GRID_DISPLAY: A new function in 4.6 version, to display
the results in grid rather than as a list.
Parameters : same as reuse_alv_list_display
ABAP Training ALV 36
The Example of a Simple List
ABAP Training ALV 37
Hierarchical Reports
Hierarchical sequential list output.
The function module is
A. Reuse_ALV_HIERSEQ_list_display
1. Export:
A. I_callback_program
B. I_callback_pf_status_set
C. I_callback_user_command
D. Is_layout
ABAP Training ALV 38
Hierarchical Reports Contd..
E. It_FIELDCAT
F. It_events
G. I_TABNAME_HEADER : name of the internal table in the program
containing the output data of the highest hierarchy level.
H. I_TABNAME_ITEM : name of the internal table in the program containing
the output data of the lowest hierarchy level.
I. IS_KEYINFO : this structure contains the header and item table field
names which link the two tables (shared key).
ABAP Training ALV 39
Hierarchical Reports Contd..
2. Tables
A. T_OUTTAB_HEADER : header table with data to be output
B. T_OUTTAB_ITEM : name of the internal table in the program
containing the output data of the lowest hierarchy level.
ABAP Training ALV 40
Hierarchical Reports Example
ABAP Training ALV 41
Block Report
This is used to display multiple lists continuously.
The important functions used in this report are:
A. REUSE_ALV_BLOCK_LIST_INIT
B. REUSE_ALV_BLOCK_LIST_APPEND
D. REUSE_ALV_BLOCK_HS_LIST_APPEND
C. REUSE_ALV_BLOCK_LIST_DISPLAY
ABAP Training ALV 42
Block Report Contd..
A. REUSE_ALV_BLOCK_LIST_INIT
Parameters:
a. I_CALLBACK_PROGRAM
b. I_CALLBACK_PF_STATUS_SET
c. I_CALLBACK_USER_COMMAND
This function module is used to set the default GUI status etc.
ABAP Training ALV 43
Block Report Contd..
B. REUSE_ALV_BLOCK_LIST_APPEND
Export :
a. IS_LAYOUT : layout settings for block
b. IT_FIELDCAT : field catalog
c. I_TABNAME : Internal table name of the output data
d. IT_EVENTS : internal table name with all
possible events
Tables :
a. T_OUTTAB : internal table with output data.
This function module adds the data to the block.
ABAP Training ALV 44
Block Report Contd..
Reuse_ALV_list_HS_append : -
Is used to append the hierarchical sequential blocks.
ABAP Training ALV 45
Block Report Contd..
C. Reuse_ALV_block_list_display
Parameters : all the parameters are optional.
This function module display the list with data appended by the above
function.
ABAP Training ALV 46
Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET,
REUSE_ALV_COMMENTARY_WRITE can be used.
Block Report Example
ABAP Training ALV 47
Internal Tables In SLIS
1. Slis_t_fieldcat_alv
This internal table contains the field attributes. This internal table can be
populated automatically by using REUSE_ALV_FIELDCATALOG_MERGE.
Important attributes:
A. Col_pos : position of the column
B. Fieldname : internal fieldname
C. tabname : internal table name
D. Ref_fieldname : fieldname (dictionary)
E. Ref_tabname : table (dictionary)
F. Key(1) : column with key-color
G. Icon(1) : icon
H. Hotspot(1) : hotspot
ABAP Training ALV 48
Internal Tables In SLIS Contd
I. Symbol(1) : symbol
J . Checkbox(1) : checkbox
K. J ust(1) : (r)ight (l)eft (c)ent
L. Do_sum(1) : sum up
M. No_out(1) : (o)blig. (X)no out
N. outputlen : output length
O. seltext-l : long key word
P. seltext_m : middle key word
Q. seltext_s : short key word
R. reptext_ddic : heading(ddic)
S. ddictxt(1) : (s)hort (m)iddle (l)ong
T. datatype : datatype
ABAP Training ALV 49
SLIS_T_EVENT
2. SLIS_T_EVENT
Internal table for storing all the possible events of the ALV. This
can be populated by the function module Reuse_alv_events_get
The columns are :
name : name of the event
form : name of the routine
ABAP Training ALV 50
Syntaxes For The Routines
I_callback_pf_status_set
Syntax :
FORM set_pf_status USING rt_extab TYPE slis_t_extab
The table RT_EXTAB contains the function codes which are hidden in the
standard interface.
I_callback_user_command
Syntax :
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
The parameter r_ucomm contains the function code.
The structure rs_selfield has the details about the current cursor position.
ABAP Training ALV 51
How to Create DYNAMIC Structures
1) Create a dynamic report inside the program.
2) Create a global internal table to store the lines of dynamic report.
Ex: DATA: BEGIN OF INCTABL OCCURS 10,
Line(72),
End of INCTABL.
3) Create a internal table like,
Data: begin of STRUCT occurs 10,
FILDNAME(25) type c,
ABPTYPE(4) type c,
Length type i,
End of STRUCT.
4) Insert the structure (dynamically) in to the internal table.
ABAP Training ALV 52
How to Create DYNAMIC Structures
3) Whole code is inside internal table INCTABL.
4) Move dynamically created report code from INCTABL to
dynamic report ZDYNPRO
Insert report 'ZDYNPRO' from INCTABL.
7. Submit the dynamic report
Submit ZDYNPRO and return.
System leaves the active program, and starts the new dynamic report
ZDYNPRO.
Once the execution is over program will use the structure which is
created dynamically.
ABAP Training ALV 53
Restrictions
Not all of the existing types of tables and lists can be replaced by one of
the ALV components.
Matrices could not be replaced by ALV.
Nets could not be replaced by ALV. (Nets are data structures with more
complex interconnections than the hierarchical ones in trees. )
There is no currency handling
Limited function compared to drilldown reporting