Vous êtes sur la page 1sur 7

ALV (ABAP List Viewer) vs.

Normal ABAP Report

Notes
Introduction.
• ALV – ABAP List Viewer (4.6B)
• ALV Grid Control vs. ALV List
• Advantages
o No huge selection screens – use filters – (moderate use!)
o Minimal maintenance if done properly
 Extract lots of data
 Work with user on possible data requirements
 Setup variants together with the user
o User-friendly functionality (Download to Excel etc.)
o Non-Static
o It is not an updating tool!
• Workings
o Grid / Report
 Moving of columns
 Total / Sub Total (Breaks) / Hide Columns
 Sort / Filter / Blank Control Breaks not on List
 Hotspots
 Multiple lines report (ALV List only)
 Buttons
 Variants (User / Set as default / “/GENERAL”)
 When it dump (Flush / CNTL-ERROR)
 Differences between 4.6B & 4.6C
• Help
o Users & ABAPers
 SAP Library ► Search Tab ► Enter “ALV Grid” ► Select “ABAP
List Viewer (ALV) Grid Control (Getting Started)”
o ABAPers
 SAP Library ► Index Tab ► Enter “ALV” ► Select “ALV Grid
Control” ► Select “BC – ALV Grid Control” (Hotspot on right-hand
panel)

ABAP ALV Report.


• Use Function Modules
• Pass parameters using fields, structures & tables
• Use dynamic events
• GUI status
• Logo in Grid – not printed or shown on print preview!

Pitfalls, Disadvantages & Tips.


• Dumps – Messages are not to useful
o Flush – CL_GUI_… (4.6B / C with latest service packs)
o Discuss Application Server vs. Presentation Server
o Check ITAB-fieldname and Initialize_ALV (Incorrect fieldnames)
• Memory block read – Shows a page of icons
• Report variant (Transportable???)
• Report cut-off after 255 columns
• Multiple lines not downloadable to Excel
• Statistics pages will have to be reported with separate button
• Zebra lines on report (not on grid)
• Colour of lines / columns – Use ‘soft’ colours (Different in 4.6C ???)
• SAP standard ALV reports – Be careful
o Not “populating” all fields of “ITAB”
o Looping through selection more than once – Some advantages
• Discuss not using huge selection screens
• Page number 0 on Grid (and after using list)
• Total number of records – create count field in ITAB
• Dialog programs – Heading only 80 columns

Additional Stuff.
• Logos
• Using ALV Grid in WANs
• Full Excel capabilities in SAP
• Using Graphs (minimal effort)

ABAP ALV Dialog Program.


• Use objects
ALV (ABAP List Viewer) vs. Normal ABAP Report

A2: ALV (ABAP List Viewer) Report - Page 1

Report ZXX0001....
* Tables, Types and Data Declaration
Tables: ....
Types: ....
Data: ....
Type-Pools: slis.
Data: .... " * (See details on following pages)

* Selection Screen
Selection Screen: ....
Select Options: ....
Parameters: ....
Parameters: p_vari like disvariant-variant default '/GENERAL'.
EVENTS
Initialization.
....
Perform Initialize_ALV.
At Selection Screen (on value request for ????).
....
At Selection-Screen on Value-Request for p_vari.
Perform F4_for_Variant.
At Selection-Screen.
Perform PAI_of_Selection_Screen.
At Line-Selection.
....
Call Transaction ....
GUI Status (Copy any BALV... program's and change)

Top-Of-Page.
Perform Headings.

Start-Of-Selection.
Perform Select_Data.
End-Of-Selection.
Perform Display_Data
Text Elements

SUBROUTINES
Form Select_Data.
Select * from ....
....
If flag = ' '.
wa_itab-linecolor = 'C000'.
flag = 'X'.
Else.
wa_itab-linecolor = 'C200'.
flag = ' '.
EndIf.
Append Wa_Itab to Itab.
EndSelect.
EndForm.
Form Display_Data.
Call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = report
is_layout = layout
i_callback_pf_status_set = status
i_callback_user_command = user_command
it_fieldcat = fldcat[]
i_save = 'A'
it_events = event[]
is_print = print ABC Company
is_variant = variant
tables Code Description T
t_outtab = itab 0001 HP Printer 3
exceptions
program_error =1 0005 PC 5
others = 2. TOTAL 8
If sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EndForm.
EndIf.
Form Top_Of_Page. " Headings
* (See details on following pages) ALV Report
EndForm.
ALV (ABAP List Viewer) vs. Normal ABAP Report

A2: ALV (ABAP List Viewer) Report - Page 2

DATA DECLARATION (ALV Specific)


* Tables, Types and Data Declaration
data: val_tab like api_vali occurs 20 with header line,
char_tab like api_char occurs 20 with header line,
att_tab like api_ch_att occurs 20 with header line,
fldcat type slis_t_fieldcat_alv with header line,
layout type slis_layout_alv occurs 0 with header line,
event type slis_t_event,
ls_event type slis_alv_event,
print type slis_print_alv,
user_command type slis_formname value 'USER_COMMAND',
status type slis_formname value 'PF_STATUS',
heading type slis_t_listheader,
variant like disvariant,
def_variant like disvariant,
variant_exit type c,
variant_def type c,
report like sy-repid,
module(2),
module_text(30),
name(50),
percentage type i,
error.
SUBROUTINES
GUI Status (Copy any BALV... program's and change)

Form Top_Of_Page.
* Prepare standard heading
refresh heading.
data: line type slis_listheader,
len type i,
pos type i,
page(4) type c.
Text Elements

len = sy-linsz. " Line width of list


if sy-pagno = 0.
sy-pagno = 1.
endif.
write sy-pagno to page.

* Determine the module heading.


perform get_module_heading using 'FI'.

* Page no. left and module description as far right as possible.


clear line.
line-typ = 'H'.
concatenate 'Pg.'
page into line-info.
pos = 60 - strlen( module_text ).
pos = pos / 2.
line-info+pos = module_text.
append line to heading.

* Report title as far right as possible.


clear line.
line-typ = 'H'.
pos = pos - 3.
line-info+pos = sy-title.
append line to heading.

* Report name, user, date/time and system details.


clear line.
line-typ = 'S'.
line-key = 'Report :'.
line-info = report.
append line to heading.

line-key = 'Userid :'.


select * from user_addr
where bname = sy-uname.
exit.
endselect.
* Continue on next page.
ALV (ABAP List Viewer) vs. Normal ABAP Report

A2: ALV (ABAP List Viewer) Report - Page 3

SUBROUTINES
if sy-subrc = 0.
concatenate user_addr-mc_namefir user_addr-mc_namelas into name
separated by space.
concatenate sy-uname '-' name into line-info separated by space.
else.
move sy-uname to line-info.
endif.
append line to heading.

line-key = 'Requested :'.


write: sy-datum to line-info using edit mask '____/__/__',
'at' to line-info+11,
sy-uzeit to line-info+14 using edit mask '__:__:__'.
append line to heading.

line-key = 'System :'.


concatenate sy-sysid ' / ' sy-mandt into line-info separated by space.
append line to heading.
line-info = sy-uname.

clear line.
line-typ = 'A'.
if not s_bukrs is initial.
write: 'Company : ' to line-info,
GUI Status (Copy any BALV... program's and change)

s_bukrs-low to line-info+29.
if not s_bukrs-high is initial.
write: 'to' to line-info+35,
s_bukrs-high to line-info+38.
endif.
append line to heading.
endif.
*
Text Elements

call function 'REUSE_ALV_COMMENTARY_WRITE'


exporting
i_logo = 'AST_LOGO'
it_list_commentary = heading.

EndForm.
Form Get_Module_Heading using p_module.
* To be displayed in the heading.

case p_module.
when 'AA'.
move 'Asset Accounting' to module_text.
when 'AM'.
move 'Asset Management' to module_text.
when 'BA'.
move 'Basis, R/3 Administration' to module_text.
when 'CA'.
move 'Cross Application' to module_text.
when 'CO'.
move 'Controlling' to module_text.
when 'EC'.
move 'Enterprise Control' to module_text.
when 'FI'.
move 'Financial Accounting' to module_text.
when 'FS'.
move 'Consolidation' to module_text.
when 'HR'.
move 'Human Recources' to module_text.
when 'GL'.
move 'General Ledger' to module_text.
when 'IM'.
move 'Inventory Management' to module_text.
when 'MM'.
move 'Material Management' to module_text.
....
endcase.

EndForm.
ALV (ABAP List Viewer) vs. Normal ABAP Report

A2: ALV (ABAP List Viewer) Report - Page 4

SUBROUTINES
Form Initialize_ALV.

variant-report = sy-repid. " This is to enable variant selection


variant-log_group = 'ZVAR'. " on screen 2 when not done on sel.scr

Perform Column using:


'BUKRS' '7' text-003 '' '' '' '',
'BUTXT' '25' text-012 '' '' '' '',
'HBKID' '10' text-004 '' '' '' '',
'BANKL' '15' text-005 '' '' '' '',
'BANKA' '60' text-006 '' '' '' '',
'BRNCH' '40' text-007 '' '' '' '',
'HKTID' '6' text-008 '' '' '' '',
'TEXT1' '50' text-009 '' '' '' '',
'BANKN' '18' text-010 '' '' '' '',
'HKONT' '15' text-011 '' '' '' ''.

* Printing layout
print-no_print_selinfos = 'X'. " display no selection infos
print-no_coverpage = 'X'.
print-reserve_lines = 1. " lines reserved for end of page
print-no_print_listinfos = 'X'. " display no listinfos

* Display options
GUI Status (Copy any BALV... program's and change)

layout-colwidth_optimize = 'X'. " no column width optimization


layout-no_colhead = ' '. " no headings
layout-no_hotspot = ' '. " headings not as hotspot
layout-zebra = 'X'. " striped pattern
layout-no_vline = ' '. " columns separated by space
layout-no_min_linesize = ' '. " line size = width of the list

* Sums
Text Elements

layout-no_sumchoice = ' '. " no choice for summing up


layout-no_totalline = ' '. " no total line
layout-no_subchoice = ' '. " no choice for subtotals
layout-no_subtotals = ' '. " no subtotals possible
layout-numc_sum = ' '. " totals for NUMC-Fields possib.
layout-totals_only = ' '. " show only totals
layout-info_fieldname = 'LINECOLOR'.

* Set up table with subroutine to be used for top-of-page processing.


report = sy-repid. " THIS IS ESSENTIAL FOR TOP-OF-PAGE & EVENTS

Call Function 'REUSE_ALV_EVENTS_GET'


exporting
i_list_type = 0
importing
et_events = event.
read table event with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to ls_event-form.
append ls_event to event.
endif.

EndForm.

Form Column using name length desc datatype dec sum noout.
clear fldcat.
fldcat-fieldname = name.
fldcat-outputlen = length.
fldcat-seltext_l = desc.
fldcat-datatype = datatype.
fldcat-decimals_out = dec.
fldcat-do_sum = sum.
fldcat-no_out = noout.
if name = 'SEL'.
fldcat-checkbox = 'X'.
endif.
append fldcat.
EndForm.
ALV (ABAP List Viewer) vs. Normal ABAP Report

A2: ALV (ABAP List Viewer) Report - Page 5

SUBROUTINES
Form F4_For_Variant.

variant-report = sy-repid.
variant-log_group = 'ZVAR'.
clear def_variant.

call function 'REUSE_ALV_VARIANT_F4'


exporting
is_variant = variant " Report name
i_save = 'A'
importing
e_exit = variant_exit
es_variant = def_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if variant_exit = space.
p_vari = def_variant-variant.
variant = def_variant. " Required for selection screen usage
endif.
endif.
GUI Status (Copy any BALV... program's and change)

EndForm.

Form PAI_of_Selection_Screen.

if not p_vari is initial.


move variant to def_variant.
move p_vari to def_variant-variant.
Text Elements

call function 'REUSE_ALV_VARIANT_EXISTENCE'


exporting
i_save = 'A'
changing
cs_variant = def_variant.
variant = def_variant.
endif.

EndForm.

Form User_Command using ucomm like sy-ucomm


rs_selfield type slis_selfield.
* Processing according to content of sy-ucomm.

case ucomm.
* At line-selection interactive event - call transaction
when '&IC1'.
* READ TABLE itab INTO itab INDEX rs_selfield-tabindex.
* CHECK NOT rs_selfield-value IS INITIAL.
* CASE rs_selfield-fieldname.
* WHEN 'VBELN'.
* SET PARAMETER ID 'AUN' FIELD rs_selfield-value.
* CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
* WHEN 'EBELN'.
* SET PARAMETER ID 'BES' FIELD rs_selfield-value.
* CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* ENDCASE.
endcase.
clear ucomm.

EndForm.

Form PF_Status using extab type slis_t_extab.

set pf-status 'STAT' excluding extab.

EndForm.

Vous aimerez peut-être aussi