Alv Programming
Alv Programming
06/2004
Contents
2
What is the ALV
3
Using the ALV
Commonly Used ALV Reporting Features
4
Using the ALV
Changing the Report Layout
By pressing the ‘Change Layout’ button, the user has access to the following formatting
features
Columns
Columns that will
will be not be
displayed displayed
in this
order
5
Using the ALV
A Formatted Report
6
Using the ALV
Creating A New Layout
7
Using the ALV
Changing Layouts
8
Programming the ALV
Programming choices
Code that you may see using the function modules Code that you may see with controls
Data: g_custom_container type ref to
CALL FUNCTION cl_gui_custom_container,
'REUSE_ALV_FIELDCATALOG_MERGE' Grid type ref to cl_gui_alv_grid
EXPORTING
i_structure_name = … Create object g_custom_container
CHANGING Exporting
ct_fieldcat = … Container_name = ‘CCCONTAINER’.
************************************************************************
START-OF-SELECTION.
************************************************************************
PERFORM load_data_table.
PERFORM build_field_catalog.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
10
Programming the ALV
The Field Catalog
•The field catalog defines the fields within your data table
that you want displayed in the ALV.
•The field catalog is an internal table of TYPE
slis_fieldcat_alv
•The TYPEs used in the ALV function modules are defined
in TYPE-POOL SLIS
11
Programming the ALV
Building the Field Catalog
Method 1
Manually in your program
*****************************************************
Form Build_field_catalog.
*****************************************************
s_fieldcat-col_pos = 1.
s_fieldcat-fieldname = 'LIFNR'.
s_fieldcat-key = 'X'.
s_fieldcat-do_sum = ' '.
s_fieldcat-no_out = ' '.
s_fieldcat-datatype = 'CHAR'.
s_fieldcat-outputlen = 10.
s_fieldcat-seltext_l = 'Vendor number'.
s_fieldcat-seltext_m = 'Vendor num'.
s_fieldcat-seltext_s = 'Vndr num'.
APPEND s_fieldcat TO t_fieldcat.
s_fieldcat-col_pos = 2.
s_fieldcat-fieldname = ‘NAME1'.
.
.
.
Endform.
12
Programming the ALV
Building the Field Catalog (cont)
Method 2
Using a structure in the Data Dictionary
*****************************************************
Form Build_field_catalog.
*****************************************************
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZPKALV1'
CHANGING
ct_fieldcat = t_fieldcat.
s_fieldcat-no_out = 'X'.
MODIFY t_fieldcat FROM s_fieldcat INDEX sy-tabix.
ENDIF.
ENDLOOP.
Endform.
13
Programming the ALV
Frequently Used Catalog Fields
No_sum Do not allow totals/subtotals for this column. Used for numeric fields like
year, document number, etc that you would not want totaled.
No_zero Space – show zeros
‘X’ – suppress zeros
Seltext_l Long field label
14
Programming the ALV
The IS_LAYOUT Structure
15
Programming the ALV
IT_SORT
• IT_SORT is an internal table that is used to set the sorting and
subtotaling of the list.
• The internal table is defined to your program as follows:
TYPE-POOLS: slis.
17
Programming the ALV
The Default GUI Status
18
Programming the ALV
Implementing A Custom GUI Status
• To implement a
custom GUI status
you should place a
copy of the 1. Press
STANDARD ALV
the copy
status
button
menu painter
this also press
the copy button
(SE41)
19
Programming the ALV
Implementing A Custom GUI Status (cont)
20
Programming the ALV
Implementing A Custom GUI Status (cont)
21
Programming the ALV
Responding To Drilldown and Custom
Functions
program_error = 1
execute for drilldown and OTHERS = 2.
custom functions.
• The subroutine name can be
any valid name although
make sure it is all capitals in
the call function statement.
22
Programming the ALV
Responding To Drilldown and Custom
Functions (cont)
Sample routine
*****************************************************************
Frequently used fields from structure SLIS_selfield
form alv_ucomm using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
Tabindex The index of the detail line in the ALV that
*****************************************************************
the user double clicked. This should
case r_ucomm.
correspond to the index in the data table.
when '&IC1'. "--- pick, doubleclick Sumindex If this is > 0 then the user double-clicked a
*--- user clicked on a subtotal line. subtotal. The number would indicate the
if rs_selfield-sumindex ne 0 and rs_selfield-tabindex = 0. occurrence of the subtotal in the list.
exit.
endif. Endsum User double-clicked the total line
23
Programming the ALV
Using Events for Headers & Footers
Your use events by associating a
subroutine in your program with an ALV
event.
Use function module Sample internal table of events
REUSE_ALV_EVENTS_GET to Event name Form name
return an internal table of all events
available in the ALV. USER_COMMAND
This list is in a structure that consists of TOP_OF_PAGE ALV_TOP_OF_PAGE
2 fields; an event name and a form name PF_STATUS_SET
Find the event in the table that you want TOP_OF_LIST
to invoke and update the form name with
the name of the subroutine in your END_OF_PAGE
program.
END_OF_LIST
*** You cannot use write statements to
produce headers and footers. You must
use function module
REUSE_ALV_COMMENTARY_WRITE. Name of routine in
Please see documentation for details. calling program
24
Programming the ALV
Using Events for Headers & Footers (cont)
Sample code to set up events table TOP_OF_PAGE event called by ALV
Data: s_events type slis_alv_event, ******************************************************
t_events type slis_t_event. form top_of_page.
******************************************************
call function 'REUSE_ALV_EVENTS_GET' refresh t_commentary.
exporting s_commentary-typ = 'H'.
i_list_type = 0 s_commentary-key = 'H Key'.
importing s_commentary-info = 'This is TOP_OF_PAGE'.
et_events = t_events. append s_commentary to t_commentary.
s_commentary-typ = 'S'.
*--- top of page
s_commentary-key = 'Vendor number'.
read table t_events into s_events
s_commentary-info = 'All'.
with key name = slis_ev_top_of_page.
append s_commentary to t_commentary.
if sy-subrc = 0.
s_commentary-typ = 'S'.
move ‘ALV_TOP_OF_PAGE' to s_events-form.
s_commentary-key = 'Vendor name'.
modify t_events from s_events index sy-tabix.
s_commentary-info = 'All'.
endif.
append s_commentary to t_commentary.
26
Programming the ALV
Questions
Contact information:
[email protected]
AIM: PaulKleiman9
27