Alv (Abap List Viewer) : Alv Documentation and Examples11
Alv (Abap List Viewer) : Alv Documentation and Examples11
Alv (Abap List Viewer) : Alv Documentation and Examples11
Sap provides a set of ALV (ABAP LIST VIEWER) function modules, which can be put into
use to embellish the output of a report. This set of ALV functions is used to enhance the
readability and functionality of any report output. Cases arise in sap when the output of
a report contains columns extending more than 255 characters in length. In such cases,
this set of ALV functions can help choose selected columns and arrange the different
columns from a report output and also save different variants for report display. This is a
very efficient tool for dynamically sorting and arranging the columns from a report
output. The report output can contain upto 90 columns in the display with the wide
array of display options.
The commonly used ALV functions used for this purpose are;
1. REUSE_ALV_VARIANT_DEFAULT_GET
2. REUSE_ALV_VARIANT_F4
3. REUSE_ALV_VARIANT_EXISTENCE
4. REUSE_ALV_EVENTS_GET
5. REUSE_ALV_COMMENTARY_WRITE
6. REUSE_ALV_FIELDCATALOG_MERGE
7. REUSE_ALV_LIST_DISPLAY
8. REUSE_ALV_GRID_DISPLAY
9. REUSE_ALV_POPUP_TO_SELECT
The different steps used for getting the above function modules into use are :
Step 1
DATA DECLARATION
Sap standard tables types taken from the type pools are: SLIS_LAYOUT_ALV ,
SLIS_T_FIELDCAT_ALV,
SLIS_T_LISTHEADER,
SLIS_T_EVENT,
SLIS_SELFIELD.
Internal tables to be used in the program declared based on the above table types
DATA: I_LAYOUT TYPE SLIS_LAYOUT_ALV,
I_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,
I_HEADING TYPE SLIS_T_LISTHEADER,
I_EVENTS TYPE SLIS_T_EVENT.
Step 2 (Optional)
1 of 34
ALV DOCUMENTATION AND EXAMPLES22
The variants in the list display can be both user-specific and general. The user can
programmatically set the initial (default) variant for list display.
The default variant can be found using the function module
'REUSE_ALV_VARIANT_DEFAULT_GET'.
Sample code:
The user can also choose from the list of existing variants using the function module
‘REUSE_ALV_VARIANT_F4’.
Step 3
A field catalog is required for every ALV list output to add desired functionality (i.e. Key,
Hotspot, Specific headings, Justify, Col. position etc) to certain fields of the output. If not
mentioned specifically, then the defaults are taken. The possible values and defaults are
listed below.
The field catalog for the output table is built-up in the caller's coding. The build-up can
be completely or partially automated by calling the REUSE_ALV_FIELDCATALOG_MERGE
module.
The minimal field catalog is documented below. This can be done in a routine using a
local variable. The user can use the other optional parameters to assign output
attributes to different fields in the output, which differ from the default.
A field catalog need not be built-up and passed explicitly only under the following
conditions:
1. The internal table to be output has the same structure as a Data Dictionary
structure, which is referred to in the internal table declaration using LIKE, or
INCLUDE STRUCTURE. In this case the attributes of the different fields is taken
directly from the table and the attributes (key fields, length, texts etc) need to
state explicitly.
2 of 34
ALV DOCUMENTATION AND EXAMPLES33
All the values entered in the catalog is specific to the particular field whose name is
entered in the fieldname FIELDNAME of the fieldcat structure. The name of the table is
also entered in the corr. Fieldname TABNAME of the structure.
The different possible attributes are:
• Row_pos (row position): Only relevant if the list output is to be multi-line (two
or three lines) by default. So, this attribute can be used maintain certain level
of alignment in the output.
Value set: 0, 1 – 3
• Col_pos (column position): This parameter is relevant when the fields in the
output are to be different from the sequence of the fields in the internal table
used for display. The parameter specifies the relative column position of
the field in the list output. The user can change the column order interactively.
If this parameter is initial for all field catalog entries, columns appear in the
internal table field sequence.
Value set: 0, 1 – 60
• Fieldname (field name): This is the name of the internal table field for which
the parameters are passed in the catalog.
Value set: internal output table field name (required parameter)
• Tabname (internal output table): Name of the internal output table that
contains the field FIELDCAT-FIELDNAME above.
Value set: SPACE, internal output table name.
• Ctabname (internal currency unit field output table): Name of the internal
output table containing the FIELDCAT-CFIELDNAME field.
3 of 34
ALV DOCUMENTATION AND EXAMPLES44
• Outputlen (column width): This parameter is used if the desired output length
for a field is desired to be different from the internal output table field. For
fields with a Data Dictionary link this parameter can be left initial. For fields
without a Data Dictionary link (program field) the parameter must be given
the value of the desired field list output length (column width).
Initial = column width is the output length of the referred Data Dictionary field
(domain).
N = column width is n characters.
Value set: 0 (initial), n.
• Key (key column): By default, the system makes some fields in the output as
key fields, provided the fields are key fields in their referencing table. Using
this parameter, fields other than key fields of the referencing table can be
made key field. This parameter is most important if the output needs to
contain some field, which are not scrollable or cannot be hidden.
If the internal output table contains fields that are key fields from different
tables, then all those fields in the report output becomes unscrollable and
cannot be hidden. So, the fields in the output internal table should not be
referenced from tables in which they are key fields. Instead, they should be
referenced to the tables in which they are not key fields, incase they are not
desired as key field in the output.
'X' = key field (key field output in color) and Key fields cannot be interactively
hidden. Parameter FIELDCAT-NO_OUT must be left initial.
Value set: SPACE, 'X'.
• Key_sel (hideable key column): This parameter is only relevant for the fields
which are made key fields using FIELDCAT-KEY = 'X'. Using this parameter the
Key field can be hidden interactively.
The user cannot change the key column sequence interactively. The output is
controlled by the FIELDCAT-NO_OUT parameter analogously to non-key fields.
Value set: SPACE, 'X'.
• No_out (field in field list): This parameter is used to remove certain fields from
the output during initial display. The user can however interactively choose
the field for output from the field list in the display variant.
'X' = field is not displayed in the current list.
Value set: SPACE, 'X'.
4 of 34
ALV DOCUMENTATION AND EXAMPLES55
• Tech (technical field): This parameter is used to make certain field display only
in the field catalog. The fields with this parameter set cannot be output in the
list nor can they be displayed interactively from the catalog.
'X' = technical field.
Value set: SPACE, 'X'.
• Fix_column (fix column): This parameter is used to fix certain columns in the
output. All columns to be fixed must have this flag, starting from the left. If a
column without this flag is output, only the columns to the left of this column
are fixed. The user can change the column fixing interactively.
Value set: SPACE, 'X'.
'X' = column fixed (does not scroll horizontally).
• Do_sum (sum over column): the user can also call this function interactively.
Value set: SPACE, 'X'.
'X' = a sum is calculated over this internal output table field.
• No_sum (sums forbidden): No sum can be calculated over this field, although
the data type of the field would allow summing.
Value set: SPACE, 'X'.
• Icon: The parameter displays certain column contents as icons. The internal
output table column contents must be valid icon strings.
Value set: SPACE, 'X'.
'X' = column contents to be output as an icon.
• Symbol: The internal output table column must be a valid symbol character.
Value set: SPACE, 'X'
'X' = column contents are to be output as a symbol.
• Just (justification): This parameter is used for alignment of the contents of the
output table. This is only relevant for CHAR or NUMC fields in the output
internal table. The justification of the column header always follows the
justification of the columns. Independent justification of the column header is
not possible.
Value set: SPACE, 'R', 'L', and ‘C’.
' ' = Default justification for this data type
5 of 34
ALV DOCUMENTATION AND EXAMPLES66
• No_sign (no +/- sign): This parameter is used to suppress the signs of the
output fields. It is only relevant for the value fields.
Value set: SPACE, 'X'.
'X' = value output without +/ sign.
The following parameters are used for customizing the texts in the heading of the
output of the columns. The texts are taken from the Data Dictionary for fields with a
Data Dictionary reference. If this is not desired, the text parameters can also be
specified. The Data Dictionary texts are then ignored.
If the user changes the column width interactively, the column header text with the
appropriate length is always used.
The interactive function 'Optimize column width' takes account of both the
field contents and the column headers: if all field contents are shorter than
the shortest column header, the column width depends on the column header.
• Ddictxt (specify text) : You can specify with values 'L', 'M', and 'S', the
keyword that should always be used as column header. If the column width
changes, no attempt is made in this case to find an appropriate header for the
new output width.
Value set: SPACE, 'L', 'M', and ‘S’.
Sample code:
Suppose I_PO_DETAILS is an internal table containing two fields EBELN (PO number) and
EBELP (PO item no).
6 of 34
ALV DOCUMENTATION AND EXAMPLES77
CLEAR L_FIELDCAT.
L_FIELDCAT-TABNAME = 'I_PO_DETAILS'.
L_FIELDCAT-FIELDNAME = 'EBELN'.
L_FIELDCAT-KEY = 'X'. “The PO no is made the key field,
“Colored and non scrollable
L_FIELDCAT-TABNAME = 'I_PO_DETAILS'.
L_FIELDCAT-FIELDNAME = 'EBELN'.
L_FIELDCAT-KEY = 'X'. “The po item no is made the key field,
“Colored and non scrollable
L_FIELDCAT-SELTEXT_S = 'Item No'.
L_FIELDCAT-SELTEXT_M = 'Item No`.
L_FIELDCAT-SELTEXT_L = 'PO Item No'.
APPEND L_FIELDCAT TO I_FIELDTAB.
CLEAR L_FIELDCAT
Step 4
The next step is to build an event table, which are used for firing both user commands
and the system dependent events i.e. top of page, end of page etc.
A list of possible events is populated into an event table (I_EVENTS) when this table is
passed to the function module REUSE_ALV_EVENT_NAMES_GET. The return table from
this function module contains all the possible events.
The function module contains following import and export parameters.
This table is of TYPE SLIS_T_EVENT and returns to the program the name of all the
possible events.
The table structure contains the fields:
I_EVENTS-NAME: Name of the Callback event.
I_EVENTS-FORM: Name of the form routine that should be called in the calling
program at the event.
7 of 34
ALV DOCUMENTATION AND EXAMPLES88
8 of 34
ALV DOCUMENTATION AND EXAMPLES99
This event table (I_EVENTS) is now checked with the desired constants. If the desired
constant is found, then the corresponding field for the FORM NAME is populated with the
name of the routine containing the corresponding event.
Sample code :
9 of 34
ALV DOCUMENTATION AND EXAMPLES1010
ENDIF.
Step 5
A layout is build for the report output list description USING the internal table declared
above (I_LAYOUT).
Output list description structure.
The parameters are described under the following heads:
• Display options
• Exceptions
• Totals
• Interaction
• Detail screen
• Display variants (only for hierarchical-sequential lists)
• Color
• Other
The layout table is of type slis_layout_alv_spec and has the following fields:
Display options
1. Colwidth_optimize (1) TYPE c: This parameter optimizes the length of the
different columns in the output. The width of the different col. now depends on
the max. Length of the data in the column.
Value set: SPACE, 'X'
'X' = optimizes the column width so that all contents are displayed completely.
10 of 34
ALV DOCUMENTATION AND EXAMPLES1111
3. No_hotspot(1) TYPE c : The heading of the report output are not output as
hotspot.
Value set: SPACE, 'X'.
'X' = column headers are not output as hotspot
6. No_min_linesize(1) TYPE c : The report line size is equal to the width of the list.
It is not relevant for block lists.
Value set: SPACE, 'X’.
'X' = line size depends on list width
' ' = Line size is set to 80 or MIN_LINESIZE (if > 0) .
8. Max_linesize LIKE sy-linsz: The default max. Linesize is 250. To change this
default value, this parameter can interactively-define the maximum list width
setting.
Value set: 0, 80 - 1020
Exceptions
11. Lights_fieldname TYPE slis_fieldname: Internal output table field containing
the codes of exceptions to be output.
Output table field code: '1' = red traffic light
'2' = yellow traffic light
'3' = green traffic light Fieldname for exception
Value set: SPACE, internal output table field name.
12. Lights_tabname TYPE slis_tabname: Name of the internal output table that
contains the field in the parameter LIGHTS_FIELDNAME. If LIGHTS_FIELDNAME is
not empty, this field must also be filled for hierarchical-sequential lists. Only
relevant for hierarchical-sequential lists.
. Value set: SPACE, internal output table name.
11 of 34
ALV DOCUMENTATION AND EXAMPLES1212
14. Lights_condense(1) TYPE c : If a list record is output with 'red traffic light',
each
Subtotal that includes this record is also output with 'red traffic light'.
Value set: SPACE, 'X'
'X' = the 'maximum' exception of the items in the subtotal is output at subtotal
level.
Sums
15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing up
Only by fieldcatalog.
Value set: SPACE, 'X'
'X' = fields which are to be summed, passed by the calling program (FIELDCAT-
DO_SUM = 'X'). The user should not be able to change this value interactively.
16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.
Value set: SPACE, 'X'
'X' = no total record is to be output. Subtotals can still be calculated and output.
The fields in the subtotals are flagged DO_SUM = 'X' in the field list.
17. No_subchoice(1) TYPE c : Does not allow the user to interactively change the
field chosen for subtotals.
Value set: SPACE, 'X'
'X' = value whose change triggers subtotals, provided by the calling program. The
user should not be able to change this value interactively.
12 of 34
ALV DOCUMENTATION AND EXAMPLES1313
' ' = In the first column of subtotal records, the subtotal is indicated by an
appropriate number of '*' by default. If the first column is not a subtotal criterion,
the string 'Total' is output after the asterisks, if the column is wide enough.
'String’ = the string passed is output after the subtotal indicated by '*', if the
column is wide enough and the first column is not a subtotal criterion. If it is a
subtotal criterion, its value is repeated after the total, if the column is wide
enough.
Interaction
25. Box_fieldname TYPE slis_fieldname: Fieldname for checkbox in the report
output. If the list has checkboxes at the start of records (for selecting several
records), this parameter contains the internal output table field name indicated
by the checkbox selection column. The field is a checkbox at the start of list
records without a list header.
Value set: SPACE, internal output table field name
26. Box_tabname TYPE slis_tabname: Name of the internal output table that
contains the field in the parameter BOX_FIELDNAME. If BOX_FIELDNAME is not
empty, this field must also be filled for hierarchical-sequential lists.
Value set: SPACE, internal output table name.
28. Expand_fieldname TYPE slis_fieldname: fieldname flag ‘expand’. The user can
show or hide the items by clicking on the folder symbol (hotspot). If the items for
a header entry are only to be read by the calling program and passed to ALV
when a header has been expanded interactively, this can be controlled via the
CALLBACK event 'ITEM_DATA_EXPAND'.
31. F2code LIKE sy-ucomm: To assign an ALV standard function code to double-
click (F2), assign the function code to this parameter. Ex.: to assign the ALV
standard function 'Detail' ('&ETA') to F2.
=> LAYOUT-F2CODE = '&ETA'.
Value set: SPACE, function code
33. Key_hotspot(1) TYPE c : The key fields are displayed as hotspot. The columns
defined in the field catalog as key fields (FIELDCAT-KEY = 'X') are output as
hotspots, i.e. clicking on a key column (highlighted in color in the list) calls the
function under F2.
Value set: SPACE, 'X'.
13 of 34
ALV DOCUMENTATION AND EXAMPLES1414
39.No_scrolling(1) TYPE c : Does not allow scrolling of the list to the right.
Value set: SPACE, 'X'.
Detailed screen
40.Detail_popup(1) TYPE c : show detail in popup.
Value set: SPACE, 'X'
' ' = List record detail display in full-screen mode, with top-of-page.
'X' = list record detail display in popup (without top-of-page).
Display variants
42. Header_text (20) TYPE c: Text for header button. Only relevant for
hierarchical-sequential lists. You can toggle between display field and field list
views via pushbuttons in the display variant definition popup for hierarchical-
14 of 34
ALV DOCUMENTATION AND EXAMPLES1515
sequential lists. The views refer to the hierarchy level of the fields. This is
technically a toggle between the header table and item table fields.
Value set: SPACE, CHAR (20)
' ' = The header table field pushbutton text is 'Header' by default.
CHAR (20) = header table field pushbutton text.
43.item_text(20) TYPE c : Text for item button. Only relevant for hierarchical-
sequential lists. You can toggle the view between the display fields and the field
list via pushbuttons in the display variant definition popup for hierarchical-
sequential lists. The views refer to the hierarchy level of the fields. This is
technically a toggle between the header table and item table fields.
Value set: SPACE, CHAR (20)
' ' = The pushbutton text for the item table fields is 'Item' by default.
CHAR (20) = item table field pushbutton text.
Colour
45. Info_fieldname TYPE slis_fieldname: infofield for listoutput. A whole list record
can be colored individually using a color code in a column of the internal output
table for the record. Assign the name of the field containing the color code to this
parameter.
Value set: SPACE, internal output table field name
The internal output table field must be of type CHAR(3).
The code must have the following syntax: 'Cxy':
C = color (all codes must start with 'C')
X = color number ('1'-'9')
Y = bold ('0' = off, '1' = on)
Others
47. List_append(1) TYPE c : no call screen. It is only useful to output block-lists
without specifying the above modules if the number of list blocks exceeds, or
may exceed, the maximum number specified in the block module documentation.
These operations are not possible for user-defined block lists.
Example code :
I_LAYOUT-f2code = ws_fcode.
I_LAYOUT-zebra = 'X'.
I_LAYOUT-colwidth_optimize = 'X'.
I_LAYOUT-no_keyfix = 'X'.
I_LAYOUT-get_selinfos = 'X'.
I_LAYOUT-no_hotspot = 'X'.
I_LAYOUT-no_input = 'X'.
15 of 34
ALV DOCUMENTATION AND EXAMPLES1616
I_LAYOUT-hotspot_fieldname = FIELDNAME.
I_LAYOUT-no_input = ‘X’.
I_LAYOUT-no_vline = `X’.
I_LAYOUT-no_colhead = ‘ ‘.
I_LAYOUT-lights_condense = ` `.
I_LAYOUT-totals_text = ` `.
I_LAYOUT-subtotals_text = ` `.
I_LAYOUT-totals_only = ` `.
I_LAYOUT-key_hotspot = ‘X’.
I_LAYOUT-detail_popup = ‘X’.
I_LAYOUT-group_change_edit = ‘X’.
I_LAYOUT-GROUP_BUTTONS = ‘X’.
Step 6
This step is required to get the selection screen information in the report output.
The prerequisite for this is to set the parameter LAYOUT-GET_SELINFOS of the
IMPORTING structure.
The parameters to be passed in the IS_SEL_HIDE table are:
o mode: 'R' = only the entries passed in the internal table IS_SEL_HIDE-
T_ENTRIES
Are output in the pop up. Selection info, which the list tool read in the
selection screen (when called by a report with a selection screen), is
replaced by the values passed.
'S' = the selection info which the list tool read in the selection screen of the
calling report are modified by the entries in the table IS_SEL_HIDE-
T_ENTRIES.
o t_entries-mode: 'A' = output the selection info for the current table record in the info
popup.
'D' = do not output select option or SELNAME parameter selection info
in the popup.
The following table fields are only used in t_entries-mode = 'A'. They contain the
selection information to be added.
• t_entries-field: DDIC field name of the field for which selection information is
to be output.
• t_entries-table: DDIC table names of t_entries-field.
• t_entries-stext: Field name in info popup.
• If t_entries-field and t_entries-table have been entered, this text is taken from
DDIC.
• t_entries-valuf: Selection condition 'from' value (external format)
• t_entries-valut: Selection condition 'to' value (external format)
• t_entries-sign0: (I)nclusive (E)xclusive
• t_entries-option: All values of the select options Option field allowed.
16 of 34
ALV DOCUMENTATION AND EXAMPLES1717
Step 6
The Table IT_SORT is populated with the sort criteria for the different fields.
The caller specifies the sorting and/or subtotaling of the basic list in the internal table
IT_SORT.
Step 7
The final step in the output of the report is the use of two ALV functions modules.
1. REUSE_ALV_FIELDCATALOG_MERGE
2. REUSE_ALV_LIST_DISPLAY
The first function module is used to pass the field catalog to the report output and
merge it with the internal output table.
FUNCTION reuse_alv_fieldcatalog_merge.
*"---------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*” IMPORTING
*" VALUE(I_PROGRAM_NAME) LIKE SY-REPID OPTIONAL
*" VALUE(I_INTERNAL_TABNAME) TYPE SLIS_TABNAME OPTIONAL
*" VALUE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL
*" VALUE(I_CLIENT_NEVER_DISPLAY) TYPE SLIS_CHAR_1
*" DEFAULT 'X'
*" VALUE(I_INCLNAME) LIKE TRDIR-NAME OPTIONAL
*" CHANGING
*" VALUE(CT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV
*" EXCEPTIONS
*" INCONSISTENT_INTERFACE
*" PROGRAM_ERROR
*"---------------------------------------------------------------------
Import parameters
I_PROGRAM_NAME: Program in which the internal output table is declared and populated
I_INTERNAL_TABNAME: Internal output table name
I_STRUCTURE_NAME: Structure name (structure, table, and view)
I_CLIENT_NEVER_DISPL: Hide client fields default ‘X’
I_INCLNAME: Data declarations include name
CHANGING parameter
CT_FIELDCAT: Field catalog with field descriptions
17 of 34
ALV DOCUMENTATION AND EXAMPLES1818
The variant based on a program-internal table should only be used for rapid prototyping
since the following restrictions apply:
1. Performance is affected since the code of the table definition must always be read
and interpreted at runtime.
Step 8
The other function module is used to display the internal output table with the contents
FUNCTION reuse_alv_list_display.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*” IMPORTING
*" VALUE(I_INTERFACE_CHECK) DEFAULT SPACE
*" VALUE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE
*" VALUE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME
*" DEFAULT SPACE
*" VALUE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME
*" DEFAULT SPACE
*" VALUE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL
*" VALUE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL
*" VALUE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
*" VALUE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL
*" VALUE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV
*" OPTIONAL
*" VALUE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL
*" VALUE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL
*" VALUE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL
*" VALUE(I_DEFAULT) DEFAULT 'X'
" VALUE(I_SAVE) DEFAULT SPACE
" VALUE(IS_VARIANT) LIKE DISVARIANT
" STRUCTURE DISVARIANT DEFAULT SPACE
" VALUE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL
" VALUE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL
" VALUE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL
" VALUE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL
" VALUE(I_SCREEN_START_COLUMN) DEFAULT 0
" VALUE(I_SCREEN_START_LINE) DEFAULT 0
" VALUE(I_SCREEN_END_COLUMN) DEFAULT 0
" VALUE(I_SCREEN_END_LINE) DEFAULT 0
" EXPORTING
" VALUE(E_EXIT_CAUSED_BY_CALLER)
" VALUE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER
" TABLES
" T_OUTTAB
" EXCEPTIONS
" PROGRAM_ERROR
18 of 34
ALV DOCUMENTATION AND EXAMPLES1919
Import parameters
I_INTERFACE_CHECK: Interface consistency check log output.
I_CALLBACK_PROGRAM: Name of the calling program
I_CALLBACK_PF_STATUS_SET: Set EXIT routine to status.
I_CALLBACK_USER_COMMAND: EXIT routine for command handling
I_STRUCTURE_NAME: Internal output table structure name
IS_LAYOUT: List layout specifications
IT_FIELDCAT: Field catalog with field descriptions
IT_EXCLUDING: Table of inactive function codes
IT_SPECIAL_GROUPS: Grouping fields for column selection
IT_SORT: Sort criteria for first list display
IT_FILTER: Filter criteria for first list output
IS_SEL_HIDE : Selection information modification
I_DEFAULT: Initial variant active/inactive logic
I_SAVE: Variants can be saved
IS_VARIANT : Variant information
IT_EVENTS: Table of events to perform
IT_EVENT_EXIT : Standard fcode exit requests table
IS_PRINT: Print information
IS_REPREP_ID: Initialization keys for Re/Re interface
I_SCREEN_START_COLUMN: Coordinates for list in dialog box
I_SCREEN_START_LINE: Coordinates for list in dialog box
I_SCREEN_END_COLUMN: Coordinates for list in dialog box
I_SCREEN_END_LINE: Coordinates for list in dialog box
IT_EVENT_EXIT: Standard fcode exit requests table
IS_PRINT: Print information
IS_REPREP_ID: Initialization keys for Re/Re interface
I_SCREEN_START_COLUMN: Coordinates for list in dialog box
I_SCREEN_START_LINE: Coordinates for list in dialog box
I_SCREEN_END_COLUMN: Coordinates for list in dialog box
I_SCREEN_END_LINE: Coordinates for list in dialog box
Export parameters
E_EXIT_CAUSED_BY_CALLER: Delete list in CALLBACK_USER_COMMAND
ES_EXIT_CAUSED_BY_USER: How the user left the list Tables
T_OUTTAB: Table with data to be displayed ---mandatory
Example Code
WS_REPNAME = SY-REPID.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
19 of 34
ALV DOCUMENTATION AND EXAMPLES2020
I_CALLBACK_PROGRAM = WS_REPNAME
I_STRUCTURE_NAME = Internal output table field name
IS_LAYOUT = I_LAYOUT
IT_FIELDCAT = I_FIELDTAB
I_DEFAULT = 'A'
I_SAVE = 'A'
IS_VARIANT = 'X'
IT_EVENTS = I_EVENTS[]
IT_SORT = I_SORT
IS_SEL_HIDE = I_SELINFO
TABLES
T_OUTTAB = Internal output table field name.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_LIST_DISPLAY'.
ENDIF
THIS IS THE POP UP TO ALLOW THE USER TO DYNAMICALLY SELECT THE FIELDS FOR
DISPLAY. HE CAN CHOOSE FROM THIS FIELDS ACC. TO REQUIREMENT AND HIDE THE
OTHER FIELDS
output.html
THE USER HAS HIDDEN SOME OF THE FIELD FROM THE TOTAL FIELDS TO CUSTOMIZE
THE REPORT OUTPUT
20 of 34
ALV DOCUMENTATION AND EXAMPLES2121
output1.html
USER CAN CHOOSE A PARTICULAR SET OF FIELD FROM THE OUTPUT AND CAN SAVE IT
AS VARIANTS
21 of 34
ALV DOCUMENTATION AND EXAMPLES2222
Using other function module 'REUSE_ALV_GRID_DISPLAY’ can help us get list output in
the form of a grid and also attach logos to the report output.
Sample code
*---------------------------------------------------------------------*
* Selection
SELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT.
22 of 34
ALV DOCUMENTATION AND EXAMPLES2323
REPORT Y_DEMO_ALV_1.
*
* Data to be displayed
DATA: I_SFLIGHT TYPE TABLE OF SFLIGHT.
*---------------------------------------------------------------------*
* Selection
SELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT.
REPORT y_demo_alv_3.
TYPE-POOLS: slis.
23 of 34
ALV DOCUMENTATION AND EXAMPLES2424
i_structure_name = 'SFLIGHT'
* IT_FIELDCAT =
* IT_EXCLUDING =
* I_CALLBACK_PROGRAM =
* I_CALLBACK_USER_COMMAND =
* IS_PRIVATE = I_PRIVATE
IMPORTING
es_selfield = i_selfield
e_exit = w_exit
TABLES
t_outtab = i_outtab
EXCEPTIONS
program_error =1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE i000(0k) WITH sy-subrc.
ENDIF.
*****the internal table is modified with a cross sign for marking the
***rows selected
24 of 34
ALV DOCUMENTATION AND EXAMPLES2525
25 of 34
ALV DOCUMENTATION AND EXAMPLES2626
*---------------------------------------------------------------------*
INITIALIZATION.
w_repid = sy-repid.
PERFORM variant_init.
* Get default variant
i_variant1 = i_variant.
IF sy-subrc = 0.
p_varnt = i_variant1-variant.
ENDIF.
* PAI
AT SELECTION-SCREEN.
PERFORM pai_of_selection_screen.
START-OF-SELECTION.
PERFORM selection.
END-OF-SELECTION.
26 of 34
ALV DOCUMENTATION AND EXAMPLES2727
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
27 of 34
ALV DOCUMENTATION AND EXAMPLES2828
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_sflight
EXCEPTIONS
program_error =1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*---------------------------------------------------------------------*
* FORM FIELDCAT_INIT *
*---------------------------------------------------------------------*
* --> L_FIELDCAT *
*---------------------------------------------------------------------*
FORM fieldcat_init USING l_fieldcat TYPE slis_t_fieldcat_alv.
28 of 34
ALV DOCUMENTATION AND EXAMPLES2929
ls_fieldcat-sp_group = 'A'.
*The field cannot be summed irrespective of its data type
ls_fieldcat-no_sum = 'X'.
APPEND ls_fieldcat TO l_fieldcat.
*
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SEATSMAX'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-sp_group = 'A'.
APPEND ls_fieldcat TO l_fieldcat.
*
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-sp_group = 'B'.
APPEND ls_fieldcat TO l_fieldcat.
*
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'CARRID'.
ls_fieldcat-outputlen = 7.
APPEND ls_fieldcat TO l_fieldcat.
ENDFORM.
*---------------------------------------------------------------------*
* FORM DATA_ADD *
*---------------------------------------------------------------------*
* --> L_SFLIGHT
*---------------------------------------------------------------------*
FORM data_add TABLES l_sflight STRUCTURE i_sflight.
LOOP AT l_sflight.
MODIFY l_sflight.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM EVENTTAB_BUILD *
*---------------------------------------------------------------------*
* --> l_EVENTS *
29 of 34
ALV DOCUMENTATION AND EXAMPLES3030
*---------------------------------------------------------------------*
FORM eventtab_build USING l_events TYPE slis_t_event.
IF sy-subrc = 0.
MOVE c_formname_top_of_page TO ls_event-form.
APPEND ls_event TO l_events.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM COMMENT_BUILD *
*---------------------------------------------------------------------*
* --> L_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM comment_build USING l_top_of_page TYPE slis_t_listheader.
***Header
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: not used for this type
ls_line-info = 'Heading list'.
APPEND ls_line TO l_top_of_page.
***Selection
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Key 1'.
ls_line-info = 'Information'.
APPEND ls_line TO l_top_of_page.
ls_line-key = 'Key 2'.
APPEND ls_line TO l_top_of_page.
***Action
CLEAR ls_line.
ls_line-typ = 'A'.
* LS_LINE-KEY: not used for this type
Ls_line-info = 'Status list'.
APPEND ls_line TO l_top_of_page.
ENDFORM.
30 of 34
ALV DOCUMENTATION AND EXAMPLES3131
*---------------------------------------------------------------------*
* FORM LAYOUT_BUILD *
*---------------------------------------------------------------------*
* <-> LS_LAYOUT *
*---------------------------------------------------------------------*
FORM layout_build USING ls_layout TYPE slis_layout_alv.
ls_layout-f2code = w_f2code.
ls_layout-zebra = p_zebra.
ls_layout-colwidth_optimize = p_colopt.
IF p_chkbox = 'X'.
*Fieldname for check box on the report output
ls_layout-box_fieldname = w_boxnam.
ELSE.
ls_layout-box_fieldname = space.
ENDIF.
ls_layout-no_input = p_noinpt.
ls_layout-no_vline = p_novlin.
ls_layout-no_colhead = p_nocolh.
IF p_lights = 'X' OR p_lightc = 'X'.
**Fieldname for lights on the report output
ls_layout-lights_fieldname = w_lignam.
ELSE.
CLEAR ls_layout-lights_fieldname.
ENDIF.
ls_layout-lights_condense = p_lightc.
ls_layout-totals_text = p_totext.
ls_layout-subtotals_text = p_sttext.
ls_layout-totals_only = p_totonl.
ls_layout-key_hotspot = p_keyhot.
ls_layout-detail_popup = p_detpop.
ls_layout-group_change_edit = p_groups.
* E05_LS_LAYOUT-GROUP_BUTTONS = P_GROUPB.
* ls_layout-group_buttons = 'X'.
ENDFORM.
*---------------------------------------------------------------------*
* FORM SP_GROUP_BUILD *
*---------------------------------------------------------------------*
* --> L_SP_GROUP *
*---------------------------------------------------------------------*
FORM sp_group_build USING l_sp_group TYPE slis_t_sp_group_alv.
CLEAR ls_sp_group.
ls_sp_group-sp_group = 'B'.
31 of 34
ALV DOCUMENTATION AND EXAMPLES3232
ENDFORM.
*---------------------------------------------------------------------*
* FORM SELECTION *
*---------------------------------------------------------------------*
FORM selection.
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM top_of_page.
*
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = i_list_top_of_page.
ENDFORM.
*---------------------------------------------------------------------*
* FORM F4_FOR_VARIANT *
*---------------------------------------------------------------------*
FORM f4_for_variant.
*
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = i_variant
i_save = w_save
* it_default_fieldcat =
IMPORTING
e_exit = w_exit
es_variant = i_variant1
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 w_exit = space.
p_varnt = i_variant1-variant.
ENDIF.
ENDIF.
32 of 34
ALV DOCUMENTATION AND EXAMPLES3333
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PAI_OF_SELECTION_SCREEN
*&---------------------------------------------------------------------*
* to check whether right variant is entered on the selection scr
*----------------------------------------------------------------------*
FORM pai_of_selection_screen.
*
IF NOT p_varnt IS INITIAL.
MOVE i_variant TO i_variant1.
MOVE p_varnt TO i_variant1-variant.
i_variant = i_variant1.
ELSE.
PERFORM variant_init.
ENDIF.
*&---------------------------------------------------------------------*
*& Form VARIANT_INIT
*----------------------------------------------------------------------*
FORM variant_init.
*
CLEAR i_variant.
i_variant-report = w_repid.
*---------------------------------------------------------------------*
* FORM PRINT_BUILD *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM print_build USING l_print TYPE slis_print_alv.
*
l_print-print = p_print.
l_print-no_print_selinfos = p_nosinf.
l_print-no_coverpage = p_nocove.
l_print-no_new_page = p_nonewp.
l_print-no_print_listinfos = p_nolinf.
l_print-reserve_lines = p_reserv.
l_print-print = p_print.
ENDFORM.
*---------------------------------------------------------------------*
33 of 34
ALV DOCUMENTATION AND EXAMPLES3434
* FORM T_SORT_BUILD *
*---------------------------------------------------------------------*
FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.
ls_sort-fieldname = 'CARRID'.
ls_sort-spos = 1.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO l_sort.
ENDFORM.
34 of 34