
An Easy Reference for ALV Grid Control
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat type lvc_s_fcat .
ls_fcat-fieldname = 'CARRID' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '3' .
ls_fcat-coltext = 'Carrier ID' .
ls_fcat-seltext = 'Carrier ID' .
APPEND ls_fcat to pt_fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'CONNID' .
ls_fcat-ref_table = 'SFLIGHT' .
ls_fcat-ref_table = 'CONNID' .
ls_fcat-outputlen = '3' .
ls_fcat-coltext = 'Connection ID' .
ls_fcat-seltext = 'Connection ID' .
APPEND ls_fcat to pt_fieldcat .
ENDFORM .
Code Part 6 –
Preparing field catalog manually
Building Field Catalog Semi-Automatically
It is a boring work to fill and append rows for all columns of our list. And it is not flexible to proceed
with automatically generating of the field catalog. Fortunately, there is a middle ground as generating the
field catalog semi-automatically.
This procedure requires a function module to call. We pass the name of the structure to be the
template and the function module generates a field catalog for us. After getting the generated field
catalog, we loop at it and change whatever we want. The name of the function module is
“
LVC_FIELDCATALOG_MERGE
”. Here is an example coding to illustrate semi-automatic field catalog
generation procedure.
© 2005 SAP AG
16

An Easy Reference for ALV Grid Control
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat type lvc_s_fcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
*--Exception handling
ENDIF.
LOOP AT pt_fieldcat INTO ls_fcat .
CASE pt_fieldcat-fieldname .
WHEN 'CARRID' .
ls_fcat-outpulen = '10' .
ls_fcat-coltext = 'Airline Carrier ID' .
MODIFY pt_fieldcat FROM ls_fcat .
WHEN 'PAYMENTSUM' .
ls_fcat-no_out = 'X' .
MODIFY pt_fieldcat FROM ls_fcat .
ENDCASE .
ENDLOOP .
ENDFORM .
Code Part 7 –
Preparing field catalog semi-automatically
© 2005 SAP AG
17

An Easy Reference for ALV Grid Control
In the sample code above, firstly a field catalog is generated. It is filled with respect to
<structure_name> (e.g. ‘
SFLIGHT
’). After filling, we have changed the output length and column text for a
column (here ‘
CARRID
’) and make another column (‘
PAYMENTSUM
’) not to be displayed.
Now that, I can hear the question “What would happen if I both pass a structure name to the
parameter ‘
I_STRUCTURE_NAME
’ and a table to the parameter ‘
IT_FIELDCATALOG
’?”. Of course, the
method gives a priority to one and it is the name of the structure passed to the parameter
‘
I_STRUCTURE_NAME
’ which has the priority.
More about what you can do with the field catalog will be discussed in “Additional Functionalities”
sections.
Layout Adjustments
It comes now painting our ALV Grid in a general aspect. To define general appearance of our ALV
Grid we fill a structure of type “
LVC_S_LAYO
”. Here is the table containing fields and their functionalities
serviced by this adjustment.
Field name
Description
Value range
CWIDTH_OPT
If this field is set, the ALV Grid Control optimizes
the column width. You can then see the column
header and the contents of the cells of this column.
SPACE, 'X'
SMALLTITLE
If this field is set, the title size in the grid control
is set to the font size of the column header.
SPACE, 'X'
GRID_TITLE
Title between grid control and toolbar
Char string of max. 70
NO_HEADERS
If this field is set, column headers are hidden.
SPACE, 'X'
NO_HGRIDLN
If this field is set, columns are displayed without
horizontal grid lines.
SPACE, 'X'
NO_MERGING
If this field is set, cells are not merged when a
column is sorted.
SPACE, 'X'
NO_ROWMARK If this field is set, the button at the beginning of a
row is hidden in selection modes cell selection (
SEL_MODE = 'D' ) and column/row selection (
SEL_MODE = 'A' ).
SPACE, 'X'
NO_TOOLBAR
If this field is set, the toolbar is hidden.
SPACE, 'X'
NO_VGRIDLN
If this field is set, columns are displayed without
vertical grid lines.
SPACE, 'X'
© 2005 SAP AG
18

An Easy Reference for ALV Grid Control
SEL_MODE
Set the selection mode (see table at C.4.).
SPACE, 'A', 'B', 'C', 'D'
EXCP_CONDS
If this field is set, the ALV also shows an
exception in the (sub)totals line. As the color for
this exception, the ALV uses the smallest
exception value ('1': red, '2': yellow, '3' green) of
the rows to which the (sub)total refers.
SPACE, 'X'
EXCP_FNAME
Field name of the output table for displaying an
exception
Char string of max. 30
EXCP_LED
The exception is not displayed as a traffic light,
but as an LED.
SPACE, 'X'
EXCP_ROLLN
Name of a data element. The F1 help for this data
element is then called for the exception column. In
addition, the long field label of the element is
displayed as the tool tip for this column.
Char string of max. 30
CTAB_FNAME
Field name in output table for coloring cells
Char string of max. 30
INFO_FNAME
Field name in output table for coloring rows
Char string of max. 30
ZEBRA
If this field is set, the list shows a striped pattern
in the print preview and when it is printed.
SPACE, 'X'
NO_TOTARR
The ALV Grid Control displays arrows in the
totals line and the subtotals line that additionally
indicate the totaling area. Set this parameter to
suppress these arrows.
SPACE, 'X'
NO_TOTEXP
An icon displayed at the beginning of a (sub)totals
line indicates whether the line has been expanded
or not. Set this parameter to suppress this icon.
SPACE, 'X'
NO_TOTLINE
If this field is set, only subtotals, but no totals, are
displayed.
SPACE, 'X'
NUMC_TOTAL
If this field is set, the user can calculate totals for
fields of data type NUMC (normally, users are not
allowed to do this).
SPACE, 'X'
TOTALS_BEF
If this field is set, the ALV displays totals
calculated as the first rows in the grid control.
Subtotals are displayed before a new value of the
subtotals criterion.
SPACE, 'X'
© 2005 SAP AG
19

An Easy Reference for ALV Grid Control
DETAILINIT
If this field is set, the detail screen also shows
columns with initial values.
SPACE, 'X'
DETAILTITL
Title in the title bar of the detail screen.
Char string of max. 30
S_DRAGDROP
Structure for Drag & Drop settings
KEYHOT
If this field is set, all key fields are hotspot-
sensitive. If a key field is clicked once, event
SPACE, 'X'
SGL_CLK_HD Enables
the
single click on column header
function. This function sorts the list in ascending
order when the column is clicked for the first time,
and then in descending order when the column is
clicked a second time.
SPACE, 'X'
STYLEFNAME
You use this field to pass the name of the cell
table for displaying cells as pushbuttons.
Char string of max. 30
Table 5 –
Fields of layout structure
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
ps_layout-grid_title = 'Flights' .
ps_layout-smalltitle = 'X' .
ENDFORM. " prepare_layout
Code Part 8 -
Filling layout structure
© 2005 SAP AG
20