ABAP ALV Layout, Field Catalog and Color Codes Reference
This reference shows how to do the common ALV tasks in both CL_GUI_ALV_GRID and CL_SALV_TABLE, with the exact field catalog and layout field names and the meaning of the C1 to C7 color codes. It is for ABAP developers on SAP NetWeaver 7.x and S/4HANA SAP GUI reports.
| Feature | CL_GUI_ALV_GRID (LVC) | CL_SALV_TABLE | Note |
|---|---|---|---|
Create and display | NEW cl_gui_alv_grid( i_parent = lo_container ), then set_table_for_first_display( EXPORTING is_layout = ls_layo CHANGING it_outtab = lt_data it_fieldcatalog = lt_fcat ) | cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv CHANGING t_table = lt_data ). lo_alv->display( ). | The grid needs a container (custom control or docking container). SALV can run fullscreen with no screen. |
Field catalog build | LVC_FIELDCATALOG_MERGE with I_STRUCTURE_NAME, then adjust LVC_S_FCAT rows | Built automatically from the table type. Change it with get_columns( ) and get_column( ) | For a local type with the grid, fill FIELDNAME, REF_TABLE and REF_FIELD yourself. |
Column texts | LVC_S_FCAT-COLTEXT, SCRTEXT_L, SCRTEXT_M, SCRTEXT_S | column->set_long_text( ), set_medium_text( ), set_short_text( ) | Texts come from the data element when REF_TABLE or the DDIC type is set. |
Checkbox column | LVC_S_FCAT-CHECKBOX = 'X' plus EDIT = 'X' for input | column_table->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ), handle event LINK_CLICK | The field should be CHAR1. In SALV the checkbox changes only when your LINK_CLICK handler flips the value and calls refresh( ). |
Editable column | LVC_S_FCAT-EDIT = 'X', register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_modified ) | Not supported as a standard feature | Call check_changed_data( ) before you read the table, or the last change is lost. |
Editable single cells | Table of LVC_S_STYL (FIELDNAME, STYLE) in each row, LVC_S_LAYO-STYLEFNAME, style cl_gui_alv_grid=>mc_style_enabled or mc_style_disabled | Not supported | The style table component must be of type LVC_T_STYL. |
Hotspot | LVC_S_FCAT-HOTSPOT = 'X', event HOTSPOT_CLICK (E_ROW_ID, E_COLUMN_ID, ES_ROW_NO) | column_table->set_cell_type( if_salv_c_cell_type=>hotspot ), event LINK_CLICK of get_event( ) (ROW, COLUMN) | Register the handler with SET HANDLER before display. |
Double click | Event DOUBLE_CLICK (E_ROW, E_COLUMN, ES_ROW_NO) | Event DOUBLE_CLICK of CL_SALV_EVENTS_TABLE (ROW, COLUMN) | SALV event object: lo_alv->get_event( ). |
Row color | LVC_S_LAYO-INFO_FNAME = name of a CHAR4 field holding Cxyz, e.g. 'C610' | Color table column (LVC_T_SCOL) set with get_columns( )->set_color_column( 'T_COLOR' ) with no FNAME for the whole row | Value format is C + color + intensified + inverse. |
Cell color | LVC_S_LAYO-CTAB_FNAME = name of a LVC_T_SCOL field; each line has FNAME and COLOR (LVC_S_COLO: COL, INT, INV) | Same LVC_T_SCOL column with FNAME filled, set via set_color_column( ) | NOKEYCOL in LVC_S_SCOL lets the color override key column color. |
Column color | LVC_S_FCAT-EMPHASIZE = 'C300' (CHAR4 Cxyz) | column_table->set_color( ls_color ) with LVC_S_COLO | Key columns keep their key color unless set otherwise. |
Optimize column width | LVC_S_LAYO-CWIDTH_OPT = 'X', or LVC_S_FCAT-COL_OPT per column | get_columns( )->set_optimize( abap_true ) | Fixed width: LVC_S_FCAT-OUTPUTLEN or column->set_output_length( ). |
Zebra stripes | LVC_S_LAYO-ZEBRA = 'X' | get_display_settings( )->set_striped_pattern( abap_true ) | Ignored for rows that carry their own color. |
Selection mode | LVC_S_LAYO-SEL_MODE: 'A', 'B', 'C', 'D' (space behaves as 'B') | get_selections( )->set_selection_mode( if_salv_c_selection_mode=>multiple ), also single, row_column, cell | B single selection, C multiple, D cell selection, A rows and columns with row buttons. Read with get_selected_rows( ). |
Grid title | LVC_S_LAYO-GRID_TITLE | get_display_settings( )->set_list_header( ) | Short single line. |
Totals and subtotals | LVC_S_FCAT-DO_SUM = 'X'; sort table LVC_T_SORT with SUBTOT = 'X' passed in IT_SORT | get_aggregations( )->add_aggregation( columnname = 'NETWR' aggregation = if_salv_c_aggregation=>total ), get_sorts( )->add_sort( columnname = 'KUNNR' subtotal = abap_true ) | Currency amounts need CFIELDNAME (or a reference) or totals mix currencies. |
Hide column | LVC_S_FCAT-NO_OUT = 'X' (user can show it) or TECH = 'X' (never shown) | column->set_visible( abap_false ) or set_technical( abap_true ) | Technical columns are not offered in the layout dialog. |
Toolbar button | Event TOOLBAR: APPEND a STB_BUTTON to e_object->mt_toolbar; event USER_COMMAND gives E_UCOMM; call set_toolbar_interactive( ) to rebuild | Container mode: get_functions( )->add_function( name, icon, text, tooltip, position ); fullscreen: set_screen_status( pfstatus, report ) with a copied GUI status; event ADDED_FUNCTION | In fullscreen SALV, add_function raises an exception; copy a standard SALV GUI status into your program and add your function codes. |
Standard functions | IT_TOOLBAR_EXCLUDING with cl_gui_alv_grid=>mc_fc_* codes | get_functions( )->set_all( abap_true ) or set_default( ) | Without set_all SALV shows no toolbar functions. |
Top of page | Event TOP_OF_PAGE (E_DYNDOC_ID type CL_DD_DOCUMENT); split the container and call list_processing_events( i_event_name = 'TOP_OF_PAGE' i_dyndoc_id = lo_doc ) | Build CL_SALV_FORM_LAYOUT_GRID (create_label, create_text with row and column), then lo_alv->set_top_of_list( lo_grid ) | SALV also has set_top_of_list_print( ) for print output. |
Refresh after data change | refresh_table_display( is_stable = ls_stbl i_soft_refresh = 'X' ) with LVC_S_STBL ROW = 'X' COL = 'X' | lo_alv->refresh( s_stable = ls_stbl refresh_mode = if_salv_c_refresh=>soft ) | Stable keeps scroll position. Use full refresh after changing the field catalog. |
Layout variants | IS_VARIANT (REPORT = sy-repid), I_SAVE = 'A', I_DEFAULT = 'X' | get_layout( )->set_key( ls_key ), set_save_restriction( if_salv_c_layout=>restrict_none ), set_default( abap_true ) | I_SAVE: space no saving, 'X' global only, 'U' user only, 'A' both. |
F4 help on a column | LVC_S_FCAT-F4AVAILABL = 'X', register_f4_for_fields( ), event ONF4 (E_FIELDNAME, ES_ROW_NO, ER_EVENT_DATA) | Not used: SALV is display only | Set er_event_data->m_event_handled = 'X' in ONF4 or the standard help also runs. |
Data changed check | Event DATA_CHANGED (ER_DATA_CHANGED type CL_ALV_CHANGED_DATA_PROTOCOL) | Not applicable | Use add_protocol_entry( ) to reject bad input per cell. |
Color code C1 (COL_HEADING) | Gray-blue | LVC_S_COLO-COL = 1 | Headings. |
Color code C2 (COL_NORMAL) | Light gray | LVC_S_COLO-COL = 2 | List body. |
Color code C3 (COL_TOTAL) | Yellow | LVC_S_COLO-COL = 3 | Totals. |
Color code C4 (COL_KEY) | Blue-green | LVC_S_COLO-COL = 4 | Key columns. |
Color code C5 (COL_POSITIVE) | Green | LVC_S_COLO-COL = 5 | Positive values or OK status. |
Color code C6 (COL_NEGATIVE) | Red | LVC_S_COLO-COL = 6 | Negative values or errors. |
Color code C7 (COL_GROUP) | Purple in the ABAP FORMAT documentation; shown orange in many current GUI themes | LVC_S_COLO-COL = 7 | Control levels and groups. |
Code format Cxyz | x = color 1 to 7, y = intensified 0 or 1, z = inverse 0 or 1, e.g. C610 bright red, C500 normal green | LVC_S_COLO: COL = x, INT = y, INV = z | Inverse 1 colors the text instead of the background. |
Field names are from DDIC structures LVC_S_FCAT, LVC_S_LAYO, LVC_S_SCOL, LVC_S_COLO, LVC_S_STYL and LVC_S_STBL; check them in SE11 on your release. Color names follow the ABAP keyword documentation for FORMAT COLOR; the exact shade depends on the SAP GUI theme.
Get an ALV report reviewed
Send us the field catalog and event code of a slow or buggy ALV report and we will point out what to fix.
Optional. The tool and every export work without this. No spam.
How to use it
Search for the task, for example checkbox, hotspot, refresh or toolbar, and read the grid column if you build with CL_GUI_ALV_GRID and a container, or the SALV column if you use CL_SALV_TABLE. The grid is the right choice when users must edit data or you need per-cell styles. SALV is quicker for display-only reports and needs no field catalog. The last rows decode the four-character color value Cxyz used in INFO_FNAME and EMPHASIZE, and the COL, INT and INV fields used in LVC_S_COLO.
Where this lives in SAP
The grid uses DDIC structures LVC_S_FCAT (field catalog line), LVC_S_LAYO (layout), LVC_S_SCOL and LVC_S_COLO (colors), LVC_S_STYL (cell styles) and LVC_S_STBL (stable refresh). Open them in SE11 to see every field for your release. The events TOOLBAR, USER_COMMAND, HOTSPOT_CLICK, DOUBLE_CLICK, TOP_OF_PAGE, ONF4 and DATA_CHANGED belong to CL_GUI_ALV_GRID; look at them in SE24. SALV wraps the same engine through CL_SALV_TABLE, CL_SALV_COLUMNS_TABLE, CL_SALV_COLUMN_TABLE and CL_SALV_EVENTS_TABLE. Demo programs starting with SALV_DEMO and BCALV in SE38 show working examples.
- SE11: LVC_S_FCAT, LVC_S_LAYO, LVC_S_SCOL.
- SE24: CL_GUI_ALV_GRID, CL_SALV_TABLE.
- SE38: SALV_DEMO_* and BCALV_* demo reports.
Worked example: color late orders red
Add a component T_COLOR of type LVC_T_SCOL to the output structure. For each late order, append a line with FNAME = 'EDATU' and COLOR-COL = 6, COLOR-INT = 1, COLOR-INV = 0. In the grid, set LVC_S_LAYO-CTAB_FNAME = 'T_COLOR'. In SALV, call lo_alv->get_columns( )->set_color_column( 'T_COLOR' ). To color the whole row instead, leave FNAME empty in SALV, or in the grid use a CHAR4 field with value C610 and point INFO_FNAME at it. Call the refresh method with a stable LVC_S_STBL after you change colors at runtime.
Common mistakes
The most common bug with editable grids is reading the internal table before calling check_changed_data( ), which leaves the last typed value out. In SALV fullscreen, add_function raises an exception: you need your own GUI status via set_screen_status. Checkbox columns in SALV do not toggle by themselves; your LINK_CLICK handler must flip the value and refresh. Totals on amount columns without a currency reference add up different currencies. TECH = 'X' hides a column from the layout dialog for good, so use NO_OUT when users may want it back.
Frequently Asked Questions
What are the ALV color codes?
Colors 1 to 7 follow the classic list colors: 1 gray-blue (heading), 2 light gray (normal), 3 yellow (total), 4 blue-green (key), 5 green (positive), 6 red (negative), 7 purple or orange depending on theme (group). In a Cxyz string, x is the color, y is intensified (0 or 1) and z is inverse (0 or 1).
How do I color a single cell in ALV?
Add a LVC_T_SCOL table to each row, append a line with FNAME set to the column and COLOR filled with COL, INT and INV. Set LVC_S_LAYO-CTAB_FNAME to that field for CL_GUI_ALV_GRID, or call set_color_column( ) on the SALV columns object.
How do I add a button to the ALV toolbar?
For CL_GUI_ALV_GRID, handle event TOOLBAR, append a STB_BUTTON with FUNCTION, ICON and TEXT to e_object->mt_toolbar, and handle USER_COMMAND for E_UCOMM. For SALV in a container use add_function( ); in fullscreen copy a GUI status and set it with set_screen_status( ), then handle ADDED_FUNCTION.
How do I refresh ALV without losing the scroll position?
Call refresh_table_display( ) on the grid with IS_STABLE filled as ROW = 'X' and COL = 'X', and I_SOFT_REFRESH = 'X' when only data changed. In SALV call refresh( ) with s_stable and refresh_mode if_salv_c_refresh=>soft. Use a full refresh if you changed the field catalog.
If you want users to ask for these report results in plain English instead of waiting for a new ALV, Netray can add a private AI layer on your SAP system on your own servers.
Related Tools
ABAP ALV Report Skeleton Generator
Enter a program name, table and selection field and get a working ABAP report that shows an ALV grid using CL_SALV_TABLE.
Developer ToolsABAP New Open SQL Syntax Reference by Release (7.40 to 7.58)
Look up each ABAP SQL feature with the classic form, the new syntax and the SAP_BASIS release that first allows it, from 7.40 SP05 to 7.58.
Developer ToolsABAP CDS Annotations Reference (Common On-Premise Annotations)
The annotations you actually write in on-premise CDS views, with allowed values, scope, effect and the difference between DDIC-based views and view entities.
SAPABAP Developer Transaction Codes Reference
A searchable cheat sheet of development, debugging, transport and monitoring transaction codes used by ABAP developers.
More Developer Tools tools
See all- SAP GUI Scripting Script Generator (Python win32com)
- ABAP Selection Screen and SELECT-OPTIONS Generator
- SAP Gateway SEGW DPC_EXT CRUD Methods Generator (ABAP)
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
Keep exploring
Free tools
- ABAP ALV Report Skeleton GeneratorEnter a program name, table and selection field and get a working ABAP report that shows an ALV grid using CL_SALV_TABLE.
- ABAP Selection Screen and SELECT-OPTIONS GeneratorBuilds a complete ABAP report with a framed selection screen, two SELECT-OPTIONS, a parameter, radio buttons that hide a field, event blocks, validation, an optional option restriction and an ALV output.
- SAP NetWeaver Release to SAP_BASIS and Kernel ReferenceWhich SAP_BASIS release belongs to each NetWeaver and ABAP Platform release, which products run on it, which kernel lines apply and how to check your own system.