You are on page 1of 60

ALV by Indrani Choudhury

date:-03/01/2007

What Is ALV

How its Differ From our Ordinary report

Common Features Of ALV

Steps to Create ALV Report

Example Output
ALV-ABAP List Viewer

Its a Programming Model to view Output With Number of


advanced Functionalities By calling Number of SAP
Defined Functions .

Its a secret of Providing Maximum User Interaction

Basically Its Of 2 Type :

Grid Display
List Display

Back
Another DEFINITION

The common features of report are column alignment,


sorting, filtering, subtotals, totals etc. To implement these,
a lot of coding and logic is to be put. To avoid that we can
use a concept called ABAP List Viewer (ALV).

Using ALV, we can have three types of reports:


1. Simple Report
2. Block Report
3. Hierarchical Sequential Report
In ordinary report ,Once If we List The Out put in The Screen
Then For Each Functionality ,we should include Coding
Accordingly inside The ABAP Program
It makes Your ABAP Code More Complex.

ALV Gives U more functionalities Like


Filtering , Hiding particular Columns etc

In ordinary ABAP Code Once if we list the output we cant


refresh the Same Screen List Except Check box etc.

Back
There are some function modules which will enable to
produce the above reports without much effort.

All the definitions of internal tables, structures


and constants are declared in a type-pool called SLIS.
SIMPLE REPORT

1. 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
Common Features of ALV

ALV Gives the Following options Below to the User After Listing
Out put to Screen
Finding Out the Details of specific records

Filter Out Put According To some Criteria

Sorting
Descending
Ascending

Hide Columns

Send Message within Same Server


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.
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
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.
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.
SIMPLE REPORT CONTD...

C . REUSE_ALV_EVENTS_GET: Returns table of possible


events for a a list type

1. 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.
SIMPLE REPORT CONTD...

2. Export:

I_list_type(a parameter we will find in the


previously discussed FMs):
0 = simple list
1 = hierarchical-sequential list
2 = simple block list
3 = hierarchical-sequential block list
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


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
INTERNAL TABLES IN SLIS

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
i. Symbol(1) : symbol
j. Checkbox(1) : checkbox
k. just(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
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
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.
Steps Involved

Step 1 : Define Type Pools which we need ( Eg.SLIS )Which


Supports ALV Function
Step 2 : Define the type groups which will be used for different
functions
Step 3 : Collect the records To be outputting into an Internal
table
Step 4 : Implement and Populate the Parameters on which the
ALV Function Using
Step 5 : Call ALV Function ( Grid / List depends on
requirement )

Step 6 : Pass Required value to the ALV Function .

Back
Example Out Put Screen

I
call function 'REUSE_ALV_GRID_DISPLAY MAINALV FUNCTION(Grid display)
exporting
i_background_id = 'ALV_BACKGROUND Background
i_callback_program = repname Program name
i_structure_name = 'ITAB2 Internal tabl
is_layout = layout layout
it_fieldcat = fieldtab layout Setting
i_default = 'X Default layout
i_save = g_save for to save varient
i_grid_title = text-101 TITLE
is_variant = g_variant Input Varient
it_events = events[] Events
tables
t_outtab = itab2. Outputiing table
if sy-subrc <> 0.
write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_LIST_DISPLAY'.
endif.
Detailing in to POP-UP
form build_layout using p_layout type
slis_layout_alv.
p_layout-f2code = f2code.
p_layout-zebra = 'X'.
p_layout-detail_popup = 'X'.
endform.
Pass F2Code to ALV-Layout Definition F2code is defined by
SAP.
Pop Up Parameter Should be X

Note :When Double Click Particular records It will bring u to


Detail popup
Filtering ,
Sorting ,
Sending message,
Downloading,
Word processing ,
Getting The print Preview

These are all SAP standard Integration to ALV Function,


But We can Control these according to our needs .
Back Code
Defining Coloumn Positions and the fields need to be
SUM,Hiding fields etc .

l_fieldcat-tabname ='ITAB2'.
l_fieldcat-sp_group = 'A'. Group Specificatio
l_fieldcat-do_sum = 'X'. Setting it to Sum
l_fieldcat-fieldname ='DMBTR'.
l_fieldcat-col_pos = pos.
l_fieldcat-seltext_m ='AMOUNT1'.
l_fieldcat-seltext_l ='AMOUNT1'.
l_fieldcat-seltext_s ='AMOUNT1'.
append l_fieldcat to p_fieldtab.
clear : l_fieldcat.
clear : l_fieldcat.
pos = pos + 1.
l_fieldcat-tabname = 'ITAB2'. Internal Table on
which we Filled The data
l_fieldcat-fix_column = 'X'. Fixing Coloumns
l_fieldcat-no_out = 'O'. Hiding Coloumn
l_fieldcat-fieldname = 'LIFNR'. Field name
l_fieldcat-col_pos = pos. Position
l_fieldcat-seltext_m ='VENDOR'. Header Text
l_fieldcat-seltext_l ='VENDOR'. Header Text
l_fieldcat-seltext_s ='VENDOR'. header text
append l_fieldcat to p_fieldtab.
clear : l_fieldcat. Clearing Fieldcat table
*** Field Cat Table Contains all the Informations abt
Layout Set
Back Code
g_save = 'A'. FOR TO SAVE VARIENT
clear g_variant.
g_variant-report = repname.
gx_variant = g_variant.
call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
exporting
i_save = g_save
changing
cs_variant = gx_variant
exceptions
not_found = 2.
if sy-subrc = 0.
p_vari = gx_variant-variant.
endif. Back
Differentiating Key Fields with Non Key
fields etc

call function 'REUSE_ALV_FIELDCATALOG_MERGE'


exporting
i_program_name = repname
i_internal_tabname = 'ITAB2
i_inclname = repname
changing
ct_fieldcat = fieldtab.
if sy-subrc <> 0.
write: 'SY-SUBRC: ', sy-subrc,
'REUSE_ALV_FIELDCATALOG_MERGE'.
endif.
Including Headers,Texts and Company Logos
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = heading.
Note : U have to Pass the Text of Logo to I_logo
parameter
Heading Contains all the text Information Eg :
Vendor Account Details , Created by etc.. In the
Example O/P
Look with Grid Display

Back
Look with List Display

back
Project Specific-Examples
check box and customized menu bar
Subtotal on Plant column
Grey out a checkbox.
Requirement:Indicates that an open order has been closed
After the open order has been closed, the box appears greyed out. So that
it need not be processed further
Double click on a column in order to navigate to various transactions
How to write the routine?
Coding requirements:-

***************************************************************
*********
* TYPE POOLS DECLARATION REQUIRED FOR ALV DISPLAY

***************************************************************
*********
type-pools: slis.

***************************************************************
*********
DATA DECLARATION REQUIRED FOR alv DISPLAY

data: i_layout type slis_layout_alv,


i_layout1 type slis_layout_alv,
i_fieldtab type slis_t_fieldcat_alv,
i_heading type slis_t_listheader,
i_events type slis_t_event,
i_sort type slis_t_sortinfo_alv,
i_extab type slis_t_extab.
Field Catalog declaration
data: l_fieldcat type slis_fieldcat_alv.

clear l_fieldcat.
l_fieldcat-col_pos = 1.
l_fieldcat-tabname = 'T_OUT' .
l_fieldcat-fieldname = 'EBELN'.
l_fieldcat-ref_tabname = 'EKPO'.
l_fieldcat-key = 'X'.
l_fieldcat-seltext_l = 'PO Number'.
l_fieldcat-reptext_ddic = 'Po No'.
append l_fieldcat to i_fieldtab.

clear l_fieldcat.
l_fieldcat-col_pos = 2.
l_fieldcat-tabname = 'T_OUT' .
l_fieldcat-fieldname = 'EBELP'.
l_fieldcat-ref_tabname = 'EKPO'.
l_fieldcat-seltext_l = 'PO Item'.
l_fieldcat-outputlen = 7.
append l_fieldcat to i_fieldtab.

Summation on numeric columns


How I have used FM
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
I_INTERFACE_CHECK =''
i_callback_program = repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'EXCEL_DOWNLOAD '
i_structure_name = 'T_OUT'
is_layout = i_layout
it_fieldcat = i_fieldtab
it_excluding = i_extab
IT_SPECIAL_GROUPS =
it_sort = i_sort
tables
t_outtab = t_out
exceptions
program_error =1
others = 2.
Routine Syntax for PF-Status
*&--------------------------------------------------------------------
-*
* FORM SET_PF_STATUS
*&--------------------------------------------------------------------
-*
form set_pf_status using r_extab type slis_t_extab.

set pf-status 'ZOPENORDER_EXCEL' excluding r_extab.

endform. "SET_PF_STATUS
Routine for USER_COMMAND
form excel_download using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.
when '&ZXL'.
perform file_header.

when '&ZRFR'.
rs_selfield-refresh = 'X'.
clear r_ucomm.
BUILD_LAYOUT

form build_layout.

i_layout-box_fieldname = 'CHECK_BOX'.

i_layout-box_tabname = 'T_OUT'.

i_layout-zebra = 'X'.
I_layout-no_input = X.

endform.
How to disable the check-box
if sy-subrc eq 0.
move '2' to w_box.
modify t_out from w_out2 index w_tabix-
value.
else.
clear w_box.
endif.
Report Header Information
What to pass to the FM
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
* I_INTERFACE_CHECK =''
i_callback_program = repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'EXCEL_DOWNLOAD'
* i_structure_name = 'T_OUT'
is_layout = i_layout
it_fieldcat = i_fieldtab
* it_excluding = i_extab
* IT_SPECIAL_GROUPS =
it_sort = i_sort
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE =''
* IS_VARIANT =''
it_events = i_events[]
Using Events
Data: i_events type slis_t_event with header line ,
i_sort type slis_t_sortinfo_alv,
i_extab type slis_t_extab,
i_list_top_of_page type slis_t_listheader with header line.

form events.
data: ls_event type slis_alv_event .
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = i_events[]
exceptions
list_type_wrong = 1
others = 2.
Create Page heading event
read table i_events with key name = slis_ev_top_of_page into
ls_event.
if sy-subrc eq 0.
g_indx1 = sy-tabix.
ls_event-form = 'PAGE_HEADINGS'.
modify i_events from ls_event index g_indx1 transporting form.
endif.
form comment_build using p_i_list_top_of_page
type slis_t_listheader.

data: ls_line type slis_listheader.

clear ls_line.
ls_line-typ = 'S'.
ls_line-key = 'User Name :'.
ls_line-info = sy-uname.
append ls_line to p_i_list_top_of_page.

clear ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Report Name :'.
ls_line-info = sy-repid..
append ls_line to p_i_list_top_of_page.
How to use the variant property
We can only see the key field
key field is mandatory and
cannot be hidden
Questions

THANKYOU !

You might also like