Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / OOPS ABAP / ALV Reporting

ALV Reporting

OOPS ABAP · ABAP Development ·

Open the interactive lesson →
  1. The ALV landscape
  2. Legacy: REUSE_ALV function modules
  3. CL_SALV_TABLE (ALV object model)
  4. CL_GUI_ALV_GRID: setup, field catalog, layout, variants
  5. Grid presentation: colours, styles, traffic lights, dropdown
  6. Grid events and editable ALV
  7. Containers, splitter, pictures, trees
  8. Example programs
  9. Interview questions

Deep reference for SAP GUI ALV: every technology, the field catalog and layout in detail, colours, styles, events, editable grids, containers and trees, plus four complete example programs. The short overview with one example per technology is on CORE ABAP › 03 Report Programming & ALV, Part 9 – read that first. ALV with IDA is in depth on ABAP on HANA › 04 ABAP SQL, ADBC & ALV IDA (short version in 1.5); event syntax (FOR EVENT, SET HANDLER) is on page 03 Exceptions, Events & Advanced OO.

All SAP GUI ALVs are classic ABAP only (not available in ABAP Cloud). They run in S/4HANA on-premise and private cloud with Standard ABAP. In ABAP Cloud a list for the user is a Fiori elements list report on CDS (1.6 and Clean Core › 02 Clean-Core Report).

Page at a glance

Mind map of the page: choosing an ALV, REUSE FMs, CL_SALV_TABLE, CL_GUI_ALV_GRID, presentation, events and editing, containers and trees, and the ABAP Cloud note

Part 1 – The ALV landscape

1.1 Evolution

Evolution of ALV: classical list, REUSE function modules, CL_GUI_ALV_GRID, SALV object model, ALV with IDA, Fiori elements
  • Classical list: selection screen → SELECT into an internal table → WRITE → output in the basic list of the list processor (also called "L.P.S.", list processing screen). Details: CORE ABAP › 03 Parts 4–7.
  • Every report, classical or ALV, follows the same 5 steps: declare data → selection screen → validate input → SELECT → present the result. Only the last step changes with ALV.
  • The SALV object model has table, tree and hierarchical-sequential classes – but no block-list class; block lists exist only as REUSE_ALV_BLOCK_LIST_*.

1.2 Technology comparison

Technology

Class / FM

Output

Editable

Container

Background

Status

ALV list

REUSE_ALV_LIST_DISPLAY

list

no

no (full screen)

yes

Legacy, classic ABAP only

ALV grid (FM)

REUSE_ALV_GRID_DISPLAY (_LVC)

grid

fcat EDIT works, not supported

no

yes (as list)

Legacy, classic ABAP only

Block list

REUSE_ALV_BLOCK_LIST_INIT / APPEND / DISPLAY

list

no

no

yes

Legacy, classic ABAP only

Hierarchical-sequential

REUSE_ALV_HIERSEQ_LIST_DISPLAY / CL_SALV_HIERSEQ_TABLE

header + item list

no

no

yes

FM legacy, SALV current – classic ABAP only

Grid control

CL_GUI_ALV_GRID

grid

yes – the standard

yes (custom, docking, splitter)

only without container

current – classic ABAP only

SALV table

CL_SALV_TABLE

grid or list

no

optional

yes (full screen)

current, read-only – classic ABAP only

ALV tree

CL_GUI_ALV_TREE

tree with columns

checkboxes only

yes

no

current – classic ABAP only

SALV tree

CL_SALV_TREE

tree

no

optional

no

current – classic ABAP only

ALV with IDA

CL_SALV_GUI_TABLE_IDA

grid, DB paging

no

optional

no

current for big data – classic ABAP only (1.5)

Fiori elements

list report on CDS + RAP / OData

browser

via RAP

–

–

strategic in S/4HANA; the only option in ABAP Cloud (1.6)

  • Classic ABAP only (not available in ABAP Cloud): every SAP GUI ALV above. ABAP for Cloud Development has no SAP GUI, no dynpros or list statements, no executable programs, and allows only released APIs – none of these classes or FMs is released. They run in S/4HANA on-premise and private cloud with Standard ABAP.
    • REUSE_ALV_* and the SLIS types are also outdated in classic ABAP: read and maintain them, don't write new ones.
  • CL_GUI_ALV_GRID remains the only supported editable SAP GUI ALV; SALV and IDA are display-only.

1.3 Choosing an ALV

Decision ladder: Fiori elements, CL_GUI_ALV_GRID, IDA, trees, CL_SALV_TABLE

1.4 Shared building blocks: SLIS vs LVC types

The field catalog is an internal table with one row per output column (name, heading, position, colour, totals, edit …). REUSE FMs use SLIS types, the grid control uses LVC types; SALV hides both behind column objects.

Purpose

REUSE FMs (type group SLIS)

CL_GUI_ALV_GRID (LVC)

Field catalog

SLIS_T_FIELDCAT_ALV

LVC_T_FCAT / LVC_S_FCAT

Layout

SLIS_LAYOUT_ALV

LVC_S_LAYO

Sort / subtotals

SLIS_T_SORTINFO_ALV

LVC_T_SORT

Filter

SLIS_T_FILTER_ALV

LVC_T_FILT

Events

SLIS_T_EVENT (name + FORM)

class events + SET HANDLER

Layout variant

DISVARIANT + I_SAVE

DISVARIANT + I_SAVE (same)

Generate catalog

REUSE_ALV_FIELDCATALOG_MERGE

LVC_FIELDCATALOG_MERGE

1.5 ALV with IDA in one minute

CL_SALV_GUI_TABLE_IDA (Integrated Data Access) is the option for large data in SAP GUI – in S/4HANA and equally in ECC on AS ABAP 7.40 SP05 or higher (EHP7 / EHP8), on HANA or any other database. You pass a table or CDS view name instead of an internal table. The ALV asks the database only for the visible rows; sorting, filtering and totals become new SQL statements that HANA runs.

REPORT zalv_demo_ida.
DATA gv_carrid TYPE sflight-carrid.
SELECT-OPTIONS so_carr FOR gv_carrid.

START-OF-SELECTION.
TRY.
" database table or DDIC view
DATA(lo_ida) = cl_salv_gui_table_ida=>create( iv_table_name = 'SFLIGHT' ).

" select-options -> named ranges; the filter runs in the database
DATA(lo_ranges) = NEW cl_salv_range_tab_collector( ).
lo_ranges->add_ranges_for_name( iv_name = 'CARRID' it_ranges = so_carr[] ).
lo_ranges->get_collected_ranges( IMPORTING et_named_ranges = DATA(lt_ranges) ).
lo_ida->set_select_options( it_ranges = lt_ranges ).

lo_ida->fullscreen( )->display( ).
CATCH cx_salv_db_connection cx_salv_db_table_not_supported
cx_salv_ida_contract_violation cx_salv_ida_unknown_name INTO DATA(lx_ida).
MESSAGE lx_ida TYPE 'I'.
ENDTRY.

A CDS view (e.g. the one from 1.6) has its own factory method – create( ) is for tables and DDIC views only:

cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = 'ZC_ALV_DEMO_FLIGHT'
)->fullscreen( )->display( ).
  • Entry points: create( iv_table_name = … ) for tables and DDIC views, create_for_cds_view( iv_cds_view_name = … ) for CDS views (CDS parameters: set_view_parameters( )). Full screen: fullscreen( )->display( ); in a container pass the container to create( ) (parameter IO_GUI_CONTAINER).
  • Use it when the table is too big for an internal table and the user only needs to look: display only, no editable cells, no background output. Field catalog, conditions, toolbar and double click: ABAP on HANA › 04, Part 11.
  • Classic ABAP only (not available in ABAP Cloud): IDA is an SAP GUI control like the other ALVs. The ABAP Cloud answer to "big list" is a Fiori elements list report, which also reads page by page (OData paging).

1.6 Clean-core alternative: Fiori elements list report on CDS

Under clean core – and always in ABAP Cloud – a read-only "ALV report" becomes a Fiori elements list report: a CDS view entity with @UI annotations, a service definition and an OData V4 service binding. No ABAP report, no selection screen, no ALV code. The full how-to (incl. a custom entity when the list needs ABAP logic) is on Clean Core › 02 Clean-Core Report; the UI side on SAP Fiori › 07 Fiori Elements.

@EndUserText.label: 'Flights for the list report'
@AccessControl.authorizationCheck: #NOT_REQUIRED  // real apps: #CHECK + access control
define view entity ZC_ALV_DEMO_FLIGHT
as select from /dmo/flight                      // ABAP Flight Reference Scenario
{
@UI.selectionField: [{ position: 10 }]      // filter bar = selection screen
@UI.lineItem:       [{ position: 10 }]      // column = field catalog row
key carrier_id,
@UI.lineItem:       [{ position: 20 }]
key connection_id,
@UI.selectionField: [{ position: 20 }]
@UI.lineItem:       [{ position: 30 }]
key flight_date,
@UI.lineItem:       [{ position: 40 }]
@Semantics.amount.currencyCode: 'currency_code'
price,
currency_code,
@UI.lineItem:       [{ position: 50 }]
seats_occupied
}

define service ZUI_ALV_DEMO_FLIGHT {
expose ZC_ALV_DEMO_FLIGHT as Flight;
}
  • Then create a service binding (e.g. ZUI_ALV_DEMO_FLIGHT_O4, binding type OData V4 – UI), publish it and open the entity with Preview – that is the running list report.

Classic ALV report

Fiori elements list report

SELECT into an internal table

CDS view entity on released SAP views or own tables

Selection screen, SELECT-OPTIONS

filter bar: @UI.selectionField, value helps

Field catalog (columns, order, texts)

@UI.lineItem position, labels from data elements or @EndUserText.label

Layout variants, sort, totals, Excel export

built in: variant management, table settings, export

Hotspot / double click to details

navigation to an object page (@UI.facet)

Editable CL_GUI_ALV_GRID

RAP business object (behaviour definition) – RAP section

AUTHORITY-CHECK in the report

CDS access control (DCL), checked by the database

Part 2 – Legacy: REUSE_ALV function modules

Legacy – know it for interviews and old Z reports. Modern replacement: CL_SALV_TABLE (display) or CL_GUI_ALV_GRID (editing). Procedure: 1 declare, 2 read data, 3 build the field catalog, 4 call REUSE_ALV_GRID_DISPLAY (or _LIST_DISPLAY).

2.1 Field catalog

  • Only T_OUTTAB is mandatory. Without field catalog information the FM cannot build columns and stops with an abort message.
  • Two ways to supply it: I_STRUCTURE_NAME = DDIC structure (all texts and properties from the dictionary), or IT_FIELDCAT = a field catalog you build.
    • With I_STRUCTURE_NAME, ALV finds columns by field name: every structure field must exist with the same name in the output table. Field order does not matter. Easiest: type the internal table with the DDIC structure.
  • Building IT_FIELDCAT:
    • Generated: REUSE_ALV_FIELDCATALOG_MERGE with I_STRUCTURE_NAME. With I_PROGRAM_NAME + I_INTERNAL_TABNAME it reads a program table – but only old DATA … LIKE / OCCURS declarations with lines ≤ 72 characters; with TYPE declarations it returns nothing.
    • Manual: one row per column. Full control, most code.
    • Semi-automatic (best): generate, then change a few rows (texts, hotspot, do_sum). Field details: CORE ABAP › 03 Part 9.1 and section 4.2 below.

2.2 Interactive FM ALV: events, user command, top of page

Events are FORM routines in your program. Pass I_CALLBACK_PROGRAM = sy-repid so ALV knows where to find them. Register them either one by one (I_CALLBACK_USER_COMMAND, I_CALLBACK_TOP_OF_PAGE, I_CALLBACK_PF_STATUS_SET, I_CALLBACK_HTML_TOP_OF_PAGE) or all at once in IT_EVENTS.

REUSE ALV callback flow: the report calls the FM with I_CALLBACK_PROGRAM and IT_EVENTS, the FM calls the FORMs by name, the FORM can request a refresh
REPORT zalv_demo_fm_grid.
TYPES: BEGIN OF ty_order,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
kunnr TYPE vbak-kunnr,
netwr TYPE vbak-netwr,
waerk TYPE vbak-waerk,
END OF ty_order.
DATA gt_orders TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY.
DATA gv_vbeln  TYPE vbak-vbeln.
SELECT-OPTIONS so_vbeln FOR gv_vbeln.

START-OF-SELECTION.
SELECT vbeln, erdat, kunnr, netwr, waerk FROM vbak
WHERE vbeln IN @so_vbeln INTO TABLE @gt_orders.

" manual SLIS catalog; ref_tabname = DDIC texts, F1 help and conversion exits
DATA(lt_fcat) = VALUE slis_t_fieldcat_alv(
( fieldname = 'VBELN' ref_tabname = 'VBAK' key = abap_true hotspot = abap_true )
( fieldname = 'ERDAT' ref_tabname = 'VBAK' )
( fieldname = 'KUNNR' ref_tabname = 'VBAK' )
( fieldname = 'NETWR' ref_tabname = 'VBAK' do_sum = abap_true cfieldname = 'WAERK' )
( fieldname = 'WAERK' ref_tabname = 'VBAK' ) ).
" IT_EVENTS: NAME = event, FORM = your subroutine (upper case)
DATA(lt_events) = VALUE slis_t_event(
( name = slis_ev_top_of_page   form = 'TOP_OF_PAGE' )
( name = slis_ev_user_command  form = 'USER_COMMAND' )
( name = slis_ev_pf_status_set form = 'SET_STATUS' ) ).
DATA(ls_layout)  = VALUE slis_layout_alv( zebra = abap_true colwidth_optimize = abap_true ).
DATA(ls_variant) = VALUE disvariant( report = sy-repid ).

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid  " where ALV looks for the FORMs
is_layout          = ls_layout
it_fieldcat        = lt_fcat
it_events          = lt_events
is_variant         = ls_variant
i_save             = 'A'
TABLES
t_outtab           = gt_orders
EXCEPTIONS
program_error      = 1
OTHERS             = 2.

FORM set_status USING rt_extab TYPE slis_t_extab.
" copy of STANDARD_FULLSCREEN from SAPLSLVC_FULLSCREEN (list FM: STANDARD from SAPLKKBL)
SET PF-STATUS 'ZSTANDARD' EXCLUDING rt_extab.
ENDFORM.

FORM user_command USING r_ucomm TYPE sy-ucomm rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.  " double click or hotspot click
DATA(lv_vbeln) = gt_orders[ rs_selfield-tabindex ]-vbeln.
SET PARAMETER ID 'AUN' FIELD lv_vbeln.
CALL TRANSACTION 'VA03' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
WHEN 'ZREFRESH'.                    " own button in ZSTANDARD
SELECT vbeln, erdat, kunnr, netwr, waerk FROM vbak
WHERE vbeln IN @so_vbeln INTO TABLE @gt_orders.
rs_selfield-refresh = abap_true.  " ALV re-displays gt_orders
ENDCASE.
ENDFORM.

FORM top_of_page.
DATA(lt_header) = VALUE slis_t_listheader(
( typ = 'H' info = 'Sales orders' )                      " H = heading
( typ = 'S' key = 'Run date:' info = |{ sy-datum DATE = USER }| )  " S = key + info
( typ = 'A' info = |{ lines( gt_orders ) } orders| ) ).  " A = action (italic)
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_header
i_logo             = 'ZALV_DEMO_LOGO'.  " object key from OAER
ENDFORM.
  • USER_COMMAND fires for every function code of the list – double click / hotspot (&IC1) and your own PF-status buttons – not only for clicks.
    • rs_selfield: tabindex (row), fieldname, value, refresh = 'X' (redisplay), row_stable / col_stable (keep scroll position).
  • REUSE_ALV_EVENTS_GET returns all event names for a list type (I_LIST_TYPE 0 = simple list, 1 = hierarchical-sequential, 2 / 3 = block lists). The classical TOP-OF-PAGE event does not work in ALV.
    • FM events (constants SLIS_EV_*): USER_COMMAND, PF_STATUS_SET, TOP_OF_PAGE, END_OF_PAGE, TOP_OF_LIST, END_OF_LIST, TOP_OF_COVERPAGE, DATA_CHANGED, SUBTOTAL_TEXT, BEFORE_LINE_OUTPUT, AFTER_LINE_OUTPUT, CALLER_EXIT, CONTEXT_MENU …
  • REUSE_ALV_COMMENTARY_WRITE writes text and logo into the TOP OF PAGE area. Call it inside the TOP_OF_PAGE FORM. Header table SLIS_T_LISTHEADER: TYP 'H' heading, 'S' key + info, 'A' action.

2.3 Logo in the header (transaction OAER)

  • Step 1: start transaction OAER directly (/nOAER).
  • Step 2: Class name PICTURES, Class type OT, Object key = any unique name (e.g. ZALV_DEMO_LOGO) → Execute.
  • Step 3: lower pane → Document types → Standard doc. types → double-click Screen → choose the image file → Continue.
  • Step 4: pass the object key as I_LOGO to REUSE_ALV_COMMENTARY_WRITE. The logo appears only in the grid display – not in list output, not when printing.

2.4 Block lists and hierarchical-sequential lists

A block list shows several unrelated tables one below the other (e.g. customers, then orders). List output only – no grid. Repeat APPEND once per block.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING i_callback_program = sy-repid.
" per block: field catalog + data
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING is_layout   = ls_layout
it_fieldcat = lt_fcat_kna1
i_tabname   = 'GT_KNA1'
it_events   = lt_events  " mandatory, may be empty
TABLES    t_outtab    = gt_kna1.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING is_layout   = ls_layout
it_fieldcat = lt_fcat_vbak
i_tabname   = 'GT_VBAK'
it_events   = lt_events
TABLES    t_outtab    = gt_vbak.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
  • Hierarchical-sequential list = header rows each followed by their items (orders + order items): FM REUSE_ALV_HIERSEQ_LIST_DISPLAY (legacy) or CL_SALV_HIERSEQ_TABLE. The binding table (SALV_T_HIERSEQ_BINDING, fields MASTER / SLAVE = field names) links the header and item key fields:
DATA(lt_binding) = VALUE salv_t_hierseq_binding( ( master = 'VBELN' slave = 'VBELN' ) ).
TRY.
cl_salv_hierseq_table=>factory(
EXPORTING t_binding_level1_level2 = lt_binding
IMPORTING r_hierseq               = DATA(lo_hierseq)
CHANGING  t_table_level1          = lt_header    " e.g. VBAK rows
t_table_level2          = lt_items ).  " e.g. VBAP rows
lo_hierseq->display( ).
CATCH cx_salv_data_error cx_salv_not_found INTO DATA(lx_salv).
MESSAGE lx_salv TYPE 'I'.
ENDTRY.

Part 3 – CL_SALV_TABLE (ALV object model)

Introduced with NetWeaver 2004. SALV wraps the older tools: CL_GUI_ALV_GRID when shown in a container, the REUSE FMs when shown full screen. factory( ) builds the field catalog from the internal table; everything else is done through getter objects. The basic example (functions, optimise, texts, sort, totals, layouts, double click) is on CORE ABAP › 03 Part 9.3 – here are the deeper features.

CL_SALV_TABLE object model: factory in the centre, getter objects for columns, functions, sorts, aggregations, layout, display settings, selections and events around it

Getter

Returns

Used for

get_functions( )

CL_SALV_FUNCTIONS_LIST

set_all( ), set_default( ), add_function( ) (container mode)

get_columns( ) / get_column( )

CL_SALV_COLUMNS_TABLE / CL_SALV_COLUMN_TABLE

texts, width, hide, hotspot / button cells, colour, exception (traffic light) and colour columns

get_sorts( ), get_aggregations( ), get_filters( )

…_SORTS, …_AGGREGATIONS, …_FILTERS

sort + subtotals, totals, filters

get_layout( )

CL_SALV_LAYOUT

user layouts (variants)

get_display_settings( )

CL_SALV_DISPLAY_SETTINGS

striped rows, title, horizontal lines

get_selections( )

CL_SALV_SELECTIONS

selection mode, get_selected_rows( )

get_event( )

CL_SALV_EVENTS_TABLE

double click, link click, own functions

set_top_of_list( ), set_screen_status( )

–

header area, own GUI status

3.1 Example: colours, traffic lights, hotspot, header and own button

REPORT zalv_demo_salv.
TYPES: BEGIN OF ty_flight,
carrid   TYPE sflight-carrid,
connid   TYPE sflight-connid,
fldate   TYPE sflight-fldate,
seatsmax TYPE sflight-seatsmax,
seatsocc TYPE sflight-seatsocc,
light    TYPE c LENGTH 1,  " exception column: 1 red, 2 yellow, 3 green
t_color  TYPE lvc_t_scol,  " row and cell colours
END OF ty_flight.

CLASS lcl_report DEFINITION.
PUBLIC SECTION.
METHODS run.
PRIVATE SECTION.
DATA mt_flights TYPE STANDARD TABLE OF ty_flight WITH EMPTY KEY.
DATA mo_alv     TYPE REF TO cl_salv_table.
METHODS set_colours.
METHODS on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
METHODS on_added_function FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function.
ENDCLASS.

CLASS lcl_report IMPLEMENTATION.
METHOD run.
SELECT carrid, connid, fldate, seatsmax, seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF TABLE @mt_flights.
set_colours( ).
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = mo_alv
CHANGING  t_table      = mt_flights ).
" own GUI status: copy SALV_STANDARD of SAPLSALV_METADATA_STATUS, add 'ZREFRESH'
mo_alv->set_screen_status( report = sy-repid pfstatus = 'ZSALV_STATUS'
set_functions = cl_salv_table=>c_functions_all ).
DATA(lo_cols) = mo_alv->get_columns( ).
lo_cols->set_optimize( abap_true ).
lo_cols->set_exception_column( 'LIGHT' ).  " traffic lights
lo_cols->set_color_column( 'T_COLOR' ).    " row / cell colours
DATA(lo_col) = CAST cl_salv_column_table( lo_cols->get_column( 'CONNID' ) ).
lo_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
lo_col = CAST #( lo_cols->get_column( 'SEATSMAX' ) ).
lo_col->set_color( VALUE #( col = col_total ) ).  " whole column yellow
mo_alv->get_sorts( )->add_sort( columnname = 'CARRID' subtotal = abap_true ).
mo_alv->get_aggregations( )->add_aggregation( columnname = 'SEATSOCC' ).
mo_alv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).
mo_alv->get_layout( )->set_key( VALUE #( report = sy-repid ) ).
mo_alv->get_layout( )->set_save_restriction( if_salv_c_layout=>restrict_none ).
DATA(lo_head) = NEW cl_salv_form_layout_grid( ).
lo_head->create_label( row = 1 column = 1 text = 'Flight occupancy' ).
lo_head->create_text( row = 2 column = 1 text = |{ lines( mt_flights ) } flights| ).
mo_alv->set_top_of_list( lo_head ).
DATA(lo_events) = mo_alv->get_event( ).
SET HANDLER on_link_click on_added_function FOR lo_events.
mo_alv->display( ).
CATCH cx_salv_error INTO DATA(lx_salv).  " superclass of all SALV exceptions
MESSAGE lx_salv TYPE 'E'.
ENDTRY.
ENDMETHOD.

METHOD set_colours.
LOOP AT mt_flights ASSIGNING FIELD-SYMBOL(<f>) WHERE seatsmax > 0.
DATA(lv_pct) = <f>-seatsocc * 100 / <f>-seatsmax.
<f>-light = COND #( WHEN lv_pct >= 95 THEN '1' WHEN lv_pct >= 70 THEN '2' ELSE '3' ).
IF lv_pct >= 95.     " empty FNAME = whole row
APPEND VALUE #( color = VALUE #( col = col_negative ) ) TO <f>-t_color.
ELSEIF lv_pct < 50.  " FNAME = one cell
APPEND VALUE #( fname = 'SEATSOCC' color = VALUE #( col = col_positive int = 1 ) )
TO <f>-t_color.
ENDIF.
ENDLOOP.
ENDMETHOD.

METHOD on_link_click.  " hotspot cell clicked
DATA(ls_f) = mt_flights[ row ].
MESSAGE |{ ls_f-carrid } { ls_f-connid }: { ls_f-seatsocc } of { ls_f-seatsmax } seats|
TYPE 'I'.
ENDMETHOD.

METHOD on_added_function.  " own button of ZSALV_STATUS
IF e_salv_function = 'ZREFRESH'.
SELECT carrid, connid, fldate, seatsmax, seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF TABLE @mt_flights.
set_colours( ).
mo_alv->refresh( ).
ENDIF.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
NEW lcl_report( )->run( ).
  • SALV can colour lines and cells, not only columns: set_color_column( ) with a LVC_T_SCOL field colours rows (empty FNAME) and cells (FNAME filled); set_color( ) colours a column.
  • Cell types via set_cell_type( ): hotspot, button, checkbox, checkbox_hotspot (events LINK_CLICK). Hide a column: set_visible( abap_false ) or set_technical( ).
  • Own buttons: full screen → own GUI status with set_screen_status( ); in a container → get_functions( )->add_function( name = … icon = … text = … tooltip = … position = … ). Both raise ADDED_FUNCTION.
  • Container mode: factory( r_container = lo_container container_name = 'CC_ALV' … ).

3.2 SALV events (CL_SALV_EVENTS_TABLE)

Event

Fires when

Parameters

DOUBLE_CLICK

double click on a cell

ROW, COLUMN

LINK_CLICK

click on a hotspot or button cell

ROW, COLUMN

ADDED_FUNCTION

own toolbar function

E_SALV_FUNCTION

BEFORE_SALV_FUNCTION / AFTER_SALV_FUNCTION

around every standard function

E_SALV_FUNCTION

TOP_OF_PAGE / END_OF_PAGE

list / print output

R_TOP_OF_PAGE / R_END_OF_PAGE, PAGE, TABLE_INDEX

3.3 Restrictions of CL_SALV_TABLE (per SAP Help)

  • At most 90 columns; column output length at most 128 characters.
  • Sorting and subtotals: at most 9 levels (columns) in total.
  • Aggregated columns must be long enough for single values and the total.
  • Only flat tables – no nested tables (deep components) as columns.
  • Not ready for input – no supported edit mode. Workarounds that reach the inner grid are unsupported; use CL_GUI_ALV_GRID for editing.
  • In a container no background mode. Full-screen SALV runs in background and writes to the spool.

3.4 Export to Excel

  • Standard toolbar of every ALV: Export → Spreadsheet (XLSX), Local file, Word processing, Send, HTML; View → Excel in-place. Remove with IT_TOOLBAR_EXCLUDING (e.g. cl_gui_alv_grid=>mc_mb_export, mc_fc_view_excel) or SALV get_functions( ).
  • In code: DATA(lv_xlsx) = mo_alv->to_xml( xml_type = if_salv_bs_xml=>c_type_xlsx ). → XSTRING for cl_gui_frontend_services=>gui_download or an e-mail attachment (CL_BCS). Background job: spool → PDF with CONVERT_ABAPSPOOLJOB_2_PDF. ABAP Cloud: XCO library XCO_CP_XLSX.

Part 4 – CL_GUI_ALV_GRID: setup, field catalog, layout, variants

Screen, custom control, container, grid and the parameters of set_table_for_first_display

4.1 Procedure and skeleton

  • 1 Create screen 0100 in the report (any dynpro – it need not be a module pool) with a custom control area, OK_CODE field and GUI status.
  • 2 PBO: create CL_GUI_CUSTOM_CONTAINER for the area, then CL_GUI_ALV_GRID with the container as parent – only once (IS NOT BOUND).
  • 3 Read data, build field catalog (mandatory) and layout (optional), register event handlers.
  • 4 set_table_for_first_display( ); later data changes → refresh_table_display( ).
  • 5 PAI: OK_CODE; Back → free the controls and LEAVE TO SCREEN 0.

This skeleton is the frame for all grid examples on this page; the modules only call methods (no FORMs).

REPORT zalv_demo_grid.
" Screen 0100: custom control 'CC_ALV', OK field OK_CODE. Flow logic:
"   PROCESS BEFORE OUTPUT. MODULE pbo_0100.   PROCESS AFTER INPUT. MODULE pai_0100.
" GUI status 'S0100': BACK, EXIT, CANCEL
DATA gv_vbeln TYPE vbak-vbeln.
SELECT-OPTIONS so_vbeln FOR gv_vbeln.
DATA ok_code TYPE sy-ucomm.

CLASS lcl_report DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ty_order,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
netwr TYPE vbak-netwr,
waerk TYPE vbak-waerk,
END OF ty_order.
METHODS: select_data,
pbo,
pai IMPORTING iv_ucomm TYPE sy-ucomm.
PRIVATE SECTION.
DATA: mt_orders    TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY,
mo_container TYPE REF TO cl_gui_custom_container,
mo_grid      TYPE REF TO cl_gui_alv_grid.
METHODS build_fcat RETURNING VALUE(rt_fcat) TYPE lvc_t_fcat.
ENDCLASS.

CLASS lcl_report IMPLEMENTATION.
METHOD select_data.
SELECT vbeln, erdat, ernam, netwr, waerk FROM vbak
WHERE vbeln IN @so_vbeln INTO TABLE @mt_orders.
ENDMETHOD.

METHOD pbo.
IF mo_grid IS BOUND.
RETURN.  " controls survive every PBO
ENDIF.
mo_container = NEW #( container_name = 'CC_ALV' ).
mo_grid      = NEW #( i_parent = mo_container ).
DATA(lt_fcat) = build_fcat( ).
mo_grid->set_table_for_first_display(
EXPORTING is_layout       = VALUE #( zebra = abap_true cwidth_opt = abap_true )
CHANGING  it_outtab       = mt_orders
it_fieldcatalog = lt_fcat ).
ENDMETHOD.

METHOD build_fcat.  " ref_table: texts, F1/F4, conversion from the dictionary
rt_fcat = VALUE #(
( fieldname = 'VBELN' ref_table = 'VBAK' key = abap_true hotspot = abap_true )
( fieldname = 'ERDAT' ref_table = 'VBAK' )
( fieldname = 'ERNAM' ref_table = 'VBAK' )
( fieldname = 'NETWR' ref_table = 'VBAK' do_sum = abap_true cfieldname = 'WAERK' )
( fieldname = 'WAERK' ref_table = 'VBAK' ) ).
ENDMETHOD.

METHOD pai.
CASE iv_ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
mo_grid->free( ).
mo_container->free( ).
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.

DATA go_report TYPE REF TO lcl_report.

START-OF-SELECTION.
go_report = NEW #( ).
go_report->select_data( ).
CALL SCREEN 100.

MODULE pbo_0100 OUTPUT.
SET PF-STATUS 'S0100'.
go_report->pbo( ).
ENDMODULE.

MODULE pai_0100 INPUT.
go_report->pai( ok_code ).
CLEAR ok_code.
ENDMODULE.
  • Without the Screen Painter: NEW cl_gui_alv_grid( i_parent = cl_gui_container=>default_screen ) (full screen; needs a screen, e.g. an empty WRITE space. list or a selection screen), or a CL_GUI_DOCKING_CONTAINER attached to the selection screen.
  • Background: cl_gui_alv_grid=>offline( ) is not initial. Create the container only in dialog and pass the (then unbound) container reference to the grid – the output then goes to the spool as a list:
IF cl_gui_alv_grid=>offline( ) IS INITIAL.   " dialog: real container
mo_container = NEW #( container_name = 'CC_ALV' ).
ENDIF.
mo_grid = NEW #( i_parent = mo_container ).  " background: unbound reference

4.2 Field catalog LVC_S_FCAT (SLIS name in brackets)

Without a field catalog the grid aborts. Build it with LVC_FIELDCATALOG_MERGE (DDIC structure → LVC_T_FCAT), manually as above, or derive it from any internal table via SALV:

TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_salv)
CHANGING  t_table      = mt_orders ).
DATA(lt_fcat) = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns      = lo_salv->get_columns( )
r_aggregations = lo_salv->get_aggregations( ) ).
CATCH cx_salv_msg.
ENDTRY.

Group

Fields

Identification

FIELDNAME, TABNAME, REF_TABLE + REF_FIELD (REF_TABNAME / REF_FIELDNAME) for DDIC texts and F4

Position / visibility

COL_POS, ROW_POS, NO_OUT (hidden, user can show it), TECH (never shown), FIX_COLUMN, KEY, KEY_SEL

Texts

COLTEXT, SCRTEXT_S / _M / _L (SELTEXT_S / _M / _L), REPTEXT, TOOLTIP

Format

OUTPUTLEN, COL_OPT, JUST, LZERO, NO_ZERO, NO_SIGN, EDIT_MASK, CONVEXIT, DECIMALS_O, DATATYPE, INTTYPE, INTLEN

Amounts / quantities

CFIELDNAME or CURRENCY, QFIELDNAME or QUANTITY (totals per currency / unit)

Presentation

EMPHASIZE ('Cxyz'), HOTSPOT, ICON, SYMBOL, CHECKBOX, STYLE, WEB_FIELD

Totals

DO_SUM, NO_SUM

Input

EDIT, F4AVAILABL, DRDN_HNDL, DRDN_FIELD, DRDN_ALIAS, CHECKTABLE, VALEXI, AUTO_VALUE

Grouping

SP_GROUP (column groups in the layout dialog)

4.3 Layout LVC_S_LAYO (SLIS_LAYOUT_ALV)

Group

Fields

Appearance

ZEBRA, CWIDTH_OPT (COLWIDTH_OPTIMIZE), GRID_TITLE, SMALLTITLE, NO_HEADERS, NO_HGRIDLN, NO_VGRIDLN, NO_TOOLBAR (hide the whole toolbar), NO_ROWMARK, NO_MERGING, KEYHOT

Selection

SEL_MODE (see 6.3), BOX_FNAME

Editing

EDIT (whole grid editable), EDIT_MODE

Pointers to extra columns

STYLEFNAME (LVC_T_STYL), INFO_FNAME (row colour CHAR4), CTAB_FNAME (LVC_T_SCOL), EXCP_FNAME (traffic light), EXCP_LED, EXCP_CONDS

Totals

NO_TOTLINE, TOTALS_BEF, NO_TOTARR, NO_TOTEXP, NUMC_TOTAL

Misc.

DETAILINIT, DETAILTITL, S_DRAGDROP, FRONTEND

4.4 Sorting, subtotals, filters

  • LVC_T_SORT (SLIS_T_SORTINFO_ALV): SPOS (sequence), FIELDNAME, UP / DOWN, SUBTOT (subtotal per value change), COMP (compress), EXPA, GROUP ('*' page break, 'UL' underline), LEVEL.
  • Totals need DO_SUM = 'X' on a numeric column. Grand total line: layout NO_TOTLINE suppresses it, TOTALS_BEF puts totals on top.
  • Own subtotal text: event SUBTOTAL_TEXT (Example 3). Filters: IT_FILTER (LVC_T_FILT); SALV: get_filters( )->add_filter( ).
  • At runtime: get_sort_criteria / set_sort_criteria, get_filter_criteria / set_filter_criteria, get_frontend_fieldcatalog / set_frontend_fieldcatalog, set_frontend_layout, then refresh.

4.5 Layout variants (saved layouts)

I_SAVE

User may save

space

nothing (layouts can be changed but not saved)

'X'

only global (cross-user) layouts – names start with '/'

'U'

only user-specific layouts

'A'

both

  • IS_VARIANT (DISVARIANT): REPORT = sy-repid is the key; HANDLE separates several grids of one program; VARIANT = layout to start with. USERNAME need not be set. I_DEFAULT = 'X' lets users mark a default layout. The same parameters exist on REUSE_ALV_GRID_DISPLAY.
  • SALV: get_layout( )->set_key( ), set_save_restriction( ), set_default( abap_true ), set_initial_layout( p_vari ).
  • Layout parameter on the selection screen:
PARAMETERS p_vari TYPE disvariant-variant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
DATA(ls_var) = VALUE disvariant( report = sy-repid ).
CALL FUNCTION 'LVC_VARIANT_F4'  " FM ALV: REUSE_ALV_VARIANT_F4
EXPORTING  is_variant = ls_var
i_save     = 'A'
IMPORTING  es_variant = ls_var
EXCEPTIONS not_found  = 1
OTHERS     = 2.
IF sy-subrc = 0.
p_vari = ls_var-variant.
ENDIF.
" display: is_variant = VALUE #( report = sy-repid variant = p_vari ) i_save = 'A'
" default in INITIALIZATION: LVC_VARIANT_DEFAULT_GET / REUSE_ALV_VARIANT_DEFAULT_GET

Part 5 – Grid presentation: colours, styles, traffic lights, dropdown

5.1 Colour codes 'Cxyz'

x = colour 1–7, y = intensified (1) or not (0), z = inverse (1) or not (0). Example: 'C510' = intensified green, 'C610' = intensified red. Constants COL_HEADING … COL_GROUP (type group COL) for LVC_S_COLO-COL.

x

Colour

Constant

Typical use

1

grey-blue

COL_HEADING

headings

2

light grey

COL_NORMAL

normal rows

3

yellow

COL_TOTAL

totals

4

blue-green

COL_KEY

key columns

5

green

COL_POSITIVE

positive / OK

6

red

COL_NEGATIVE

negative / error

7

orange

COL_GROUP

groups

Colour a …

CL_GUI_ALV_GRID

CL_SALV_TABLE

REUSE FMs (SLIS)

Column

fcat EMPHASIZE = 'C300'

column set_color( VALUE #( col = … ) )

fcat EMPHASIZE

Row

extra CHAR4 field + layout INFO_FNAME

set_color_column( ), row with empty FNAME

layout INFO_FIELDNAME

Cell

extra LVC_T_SCOL field + layout CTAB_FNAME

set_color_column( ), FNAME = column

layout COLTAB_FIELDNAME (SLIS_T_SPECIALCOL_ALV)

5.2 One example: row / cell colours, traffic light, button cells, dropdown

All of these work the same way: add an extra field to the output table, fill it per row, and point the layout (or field catalog) to it. Extra fields named in the layout are not listed in the field catalog.

Extra fields ROWCOLOR, T_SCOL, LIGHT and T_STYL, the layout fields INFO_FNAME, CTAB_FNAME, EXCP_FNAME and STYLEFNAME, and the visual result
TYPES: BEGIN OF ty_out,
vbeln    TYPE vbak-vbeln,
netwr    TYPE vbak-netwr,
waerk    TYPE vbak-waerk,
priority TYPE c LENGTH 10,  " dropdown column
action   TYPE c LENGTH 10,  " button cells
rowcolor TYPE c LENGTH 4,   " -> INFO_FNAME (must be CHAR4)
light    TYPE c LENGTH 1,   " -> EXCP_FNAME: 1 red, 2 yellow, 3 green
t_scol   TYPE lvc_t_scol,   " -> CTAB_FNAME
t_styl   TYPE lvc_t_styl,   " -> STYLEFNAME
END OF ty_out.

LOOP AT mt_out ASSIGNING FIELD-SYMBOL(<o>).
<o>-light = COND #( WHEN <o>-netwr > 100000 THEN '3' WHEN <o>-netwr > 0 THEN '2' ELSE '1' ).
IF <o>-netwr = 0.
<o>-rowcolor = 'C610'.    " whole row red
" LVC_T_STYL is SORTED by FIELDNAME: INSERT … INTO TABLE, never APPEND out of order
INSERT VALUE #( fieldname = 'PRIORITY' style = cl_gui_alv_grid=>mc_style_disabled )
INTO TABLE <o>-t_styl.  " no input in this cell
ELSE.
<o>-action = 'Details'.
INSERT VALUE #( fieldname = 'ACTION' style = cl_gui_alv_grid=>mc_style_button )
INTO TABLE <o>-t_styl.  " this cell is a button
ENDIF.
IF <o>-netwr > 100000.
<o>-t_scol = VALUE #( ( fname = 'NETWR' color = VALUE #( col = col_positive int = 1 ) ) ).
ENDIF.
ENDLOOP.

DATA(lt_fcat) = VALUE lvc_t_fcat(
( fieldname = 'VBELN'    ref_table = 'VBAK' hotspot = abap_true )
( fieldname = 'NETWR'    ref_table = 'VBAK' cfieldname = 'WAERK' do_sum = abap_true )
( fieldname = 'WAERK'    ref_table = 'VBAK' emphasize = 'C300' )  " yellow column
( fieldname = 'PRIORITY' coltext = 'Priority' edit = abap_true drdn_hndl = 1 outputlen = 10 )
( fieldname = 'ACTION'   coltext = 'Action' ) ).
DATA(ls_layout) = VALUE lvc_s_layo( info_fname = 'ROWCOLOR' ctab_fname = 'T_SCOL'
excp_fname = 'LIGHT'    stylefname = 'T_STYL'
cwidth_opt = abap_true  sel_mode   = 'A' ).
" dropdown values BEFORE the first display
mo_grid->set_drop_down_table( it_drop_down = VALUE #( ( handle = 1 value = 'LOW' )
( handle = 1 value = 'MEDIUM' )
( handle = 1 value = 'HIGH' ) ) ).
mo_grid->set_table_for_first_display( EXPORTING is_layout       = ls_layout
CHANGING  it_outtab       = mt_out
it_fieldcatalog = lt_fcat ).
  • Styles: constants are MC_STYLE_…: MC_STYLE_BUTTON, MC_STYLE_HOTSPOT, MC_STYLE_DISABLED, MC_STYLE_ENABLED, MC_STYLE_F4. Whole column as button: fcat STYLE = cl_gui_alv_grid=>mc_style_button; single cells: LVC_T_STYL + layout STYLEFNAME.
  • Button clicks raise BUTTON_CLICK; hotspot clicks raise HOTSPOT_CLICK (Part 6).
  • Traffic lights: codes '1' / '2' / '3' in a CHAR1 field + layout EXCP_FNAME; shown as the first column; EXCP_LED = 'X' shows LEDs instead of lights.
    • Light at another position: an icon column instead – fcat ICON = 'X' plus COL_POS, value icon_green_light / icon_yellow_light / icon_red_light (type group ICON; FM ICON_CREATE adds a text or tooltip); then do not set EXCP_FNAME. The ICON constants belong to this method, not to the 1/2/3 codes.
  • Dropdown: fcat DRDN_HNDL + EDIT, values via set_drop_down_table( ) before the first display. Different list per row: DRDN_FIELD names a field holding the handle. Key + text pairs: LVC_T_DRAL (parameter IT_DROP_DOWN_ALIAS) + fcat DRDN_ALIAS.

Part 6 – Grid events and editable ALV

Event flow: user action, grid raises event, handler method, logic, refresh

6.1 Standard events vs your own events

Step

Your own (custom) events

Standard ALV events

Declare

EVENTS in your class definition

already declared by SAP in CL_GUI_ALV_GRID

Handler

method FOR EVENT … OF your_class

method FOR EVENT … OF cl_gui_alv_grid

Raise

RAISE EVENT in your methods

SAP raises them on user actions

Register

SET HANDLER … FOR object

SET HANDLER … FOR mo_grid (before the event can happen)

6.2 Event reference CL_GUI_ALV_GRID

Event

Fires when

Main parameters

TOOLBAR

at first display and on set_toolbar_interactive( )

E_OBJECT (MT_TOOLBAR), E_INTERACTIVE

USER_COMMAND

own toolbar button or own menu entry

E_UCOMM

BEFORE_ / AFTER_USER_COMMAND

every function, also standard ones

E_UCOMM

MENU_BUTTON

own menu button (BUTN_TYPE 1 / 2) clicked

E_OBJECT (CL_CTMENU), E_UCOMM

CONTEXT_MENU_REQUEST

right click

E_OBJECT (CL_CTMENU)

HOTSPOT_CLICK

single click on a hotspot cell

E_ROW_ID, E_COLUMN_ID, ES_ROW_NO

DOUBLE_CLICK

double click on any cell

E_ROW, E_COLUMN, ES_ROW_NO

BUTTON_CLICK

click on a button cell

ES_COL_ID, ES_ROW_NO

DATA_CHANGED

edited values are passed to the program (6.4)

ER_DATA_CHANGED, E_ONF4, E_UCOMM

DATA_CHANGED_FINISHED

after the output table was updated

E_MODIFIED, ET_GOOD_CELLS

ONF4

F4 on a column registered with register_f4_for_fields( )

E_FIELDNAME, ES_ROW_NO, ER_EVENT_DATA

TOP_OF_PAGE

raised by list_processing_events( ) (Example 1)

E_DYNDOC_ID

PRINT_TOP_OF_PAGE / _END_OF_PAGE / _TOP_OF_LIST / _END_OF_LIST

output as list: Print button or background

– (use WRITE)

SUBTOTAL_TEXT

for each subtotal line (Example 3)

ES_SUBTOTTXT_INFO, EP_SUBTOT_LINE, E_EVENT_DATA

ONDRAG / ONDROP / ONDROPCOMPLETE

drag & drop (layout S_DRAGDROP)

E_ROW, E_COLUMN, E_DRAGDROPOBJ

AFTER_REFRESH, DELAYED_CHANGED_SEL_CALLBACK

after refresh / selection changed (register_delayed_event( ))

–

6.3 Toolbar, user command, clicks and selected rows – one handler set

Handler methods can sit in a separate lcl_handler class or – as here – in the report class itself. Additions to the skeleton of 4.1 (output table mt_out of type ty_out from 5.2):

" --- definition (PRIVATE SECTION)
METHODS: on_toolbar      FOR EVENT toolbar       OF cl_gui_alv_grid IMPORTING e_object,
on_menu_button  FOR EVENT menu_button   OF cl_gui_alv_grid IMPORTING e_object e_ucomm,
on_user_command FOR EVENT user_command  OF cl_gui_alv_grid IMPORTING e_ucomm,
on_hotspot      FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id,
on_double_click FOR EVENT double_click  OF cl_gui_alv_grid IMPORTING e_row e_column,
on_button_click FOR EVENT button_click  OF cl_gui_alv_grid
IMPORTING es_col_id es_row_no.

" --- in pbo, BEFORE set_table_for_first_display (TOOLBAR fires during the first display)
SET HANDLER on_toolbar on_menu_button on_user_command
on_hotspot on_double_click on_button_click FOR mo_grid.
DATA(lt_exclude) = VALUE ui_functions( ( cl_gui_alv_grid=>mc_fc_print )
( cl_gui_alv_grid=>mc_fc_views ) ).
mo_grid->set_table_for_first_display(
EXPORTING is_layout            = ls_layout   " sel_mode = 'A'
it_toolbar_excluding = lt_exclude  " hide standard buttons
CHANGING  it_outtab = mt_out  it_fieldcatalog = lt_fcat ).

" --- implementation
METHOD on_toolbar.
APPEND VALUE #( butn_type = 3 ) TO e_object->mt_toolbar.          " separator
APPEND VALUE #( function = 'ZAPPROVE' icon = icon_okay text = 'Approve'
quickinfo = 'Approve selected orders' ) TO e_object->mt_toolbar.
APPEND VALUE #( function = 'ZMORE' text = 'More' butn_type = 2 )  " menu button
TO e_object->mt_toolbar.
ASSIGN e_object->mt_toolbar[ function = cl_gui_alv_grid=>mc_fc_info ] TO FIELD-SYMBOL(<b>).
IF sy-subrc = 0.
<b>-disabled = abap_true.  " grey out a std button
ENDIF.
ENDMETHOD.

METHOD on_menu_button.
IF e_ucomm = 'ZMORE'.
e_object->add_function( fcode = 'ZXLSX' text = 'Download as XLSX' ).
e_object->add_function( fcode = 'ZMAIL' text = 'Send by e-mail' ).
ENDIF.
ENDMETHOD.

METHOD on_user_command.  " own buttons and menu entries only
CASE e_ucomm.
WHEN 'ZAPPROVE'.
mo_grid->get_selected_rows( IMPORTING et_index_rows = DATA(lt_rows) ).
IF lt_rows IS INITIAL.
MESSAGE 'Select at least one row' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
LOOP AT lt_rows INTO DATA(ls_row).
mt_out[ ls_row-index ]-light = '3'.
ENDLOOP.
mo_grid->refresh_table_display( is_stable = VALUE #( row = abap_true col = abap_true ) ).
WHEN 'ZXLSX' OR 'ZMAIL'.
" export, see 3.4
ENDCASE.
ENDMETHOD.

METHOD on_hotspot.
IF e_column_id-fieldname = 'VBELN'.
DATA(lv_vbeln) = mt_out[ e_row_id-index ]-vbeln.
SET PARAMETER ID 'AUN' FIELD lv_vbeln.
CALL TRANSACTION 'VA03' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
ENDIF.
ENDMETHOD.

METHOD on_double_click.
CHECK e_row-rowtype IS INITIAL.  " not on total / subtotal lines
MESSAGE |Order { mt_out[ e_row-index ]-vbeln }, column { e_column-fieldname }| TYPE 'I'.
ENDMETHOD.

METHOD on_button_click.
MESSAGE |Button { es_col_id-fieldname } in row { es_row_no-row_id }| TYPE 'I'.
ENDMETHOD.
  • Exclude all standard buttons: cl_gui_alv_grid=>mc_fc_excl_all; hide the whole toolbar: layout NO_TOOLBAR = 'X'. Function codes are the public constants MC_FC_… (buttons) and MC_MB_… (menus).
  • Toolbar BUTN_TYPE: 0 button, 1 menu + default button, 2 menu, 3 separator; fields FUNCTION, ICON, QUICKINFO, TEXT, DISABLED. To change it later, call set_toolbar_interactive( ) – TOOLBAR fires again.
  • Order for own codes: BEFORE_USER_COMMAND → USER_COMMAND → AFTER_USER_COMMAND (also for menu entries of toolbar menu buttons).
  • USER_COMMAND fires only for own codes. BEFORE_USER_COMMAND / AFTER_USER_COMMAND also fire for standard functions; set_user_command( space ) in BEFORE_USER_COMMAND cancels a standard function.
  • Context menu: handle CONTEXT_MENU_REQUEST and call e_object->add_function( ); the chosen entry arrives in USER_COMMAND.
  • After any change to the output table call refresh_table_display( ) – not only after navigation. is_stable keeps the scroll position, i_soft_refresh = 'X' keeps sort and filter.
  • Grid events are system events: the handler runs without PAI. To force PAI afterwards (e.g. to leave the screen) call cl_gui_cfw=>set_new_ok_code( 'ZLEAVE' ).
  • Selection: layout SEL_MODE – space / 'B' single row, 'C' multiple rows, 'D' cells, 'A' rows and columns with selection buttons. Read with get_selected_rows( ) (ET_INDEX_ROWS LVC_T_ROW, ET_ROW_NO LVC_T_ROID), get_selected_cells( ), get_current_cell( ); set with set_selected_rows( ).

6.4 Editable ALV

Steps: make columns editable → register DATA_CHANGED (+ optional extra trigger) → validate in the handler → save in PAI on an explicit SAVE button.

Editable grid flow: user edits, trigger, DATA_CHANGED validates, DATA_CHANGED_FINISHED, SAVE in PAI with check, lock, authority, update, commit

When does DATA_CHANGED fire?

Setting

Check icon in the grid toolbar, any toolbar function, check_changed_data( ) in PAI

always – no registration needed

… additionally when the user presses Enter

register_edit_event( cl_gui_alv_grid=>mc_evt_enter )

… additionally as soon as the cursor leaves a modified cell

register_edit_event( cl_gui_alv_grid=>mc_evt_modified )

  • MC_EVT_MODIFIED and MC_EVT_ENTER both allow editing many cells; they only choose the extra trigger. Many programs register both.
" --- definition
DATA mt_flights      TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.
DATA mt_changed_rows TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line.
METHODS: on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed,
on_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells,
save.

" --- pbo: fcat row ( fieldname = 'PRICE' ref_table = 'SFLIGHT' edit = abap_true )
SET HANDLER on_data_changed on_data_changed_finished FOR mo_grid.
mo_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_enter ).

" --- implementation
METHOD on_data_changed.  " validate only – the grid copies correct values itself
DATA lv_price TYPE sflight-price.
LOOP AT er_data_changed->mt_mod_cells INTO DATA(ls_mod) WHERE fieldname = 'PRICE'.
er_data_changed->get_cell_value( EXPORTING i_row_id    = ls_mod-row_id
i_fieldname = ls_mod-fieldname
IMPORTING e_value     = lv_price ).
IF lv_price <= 0.
er_data_changed->add_protocol_entry( i_msgid = '00' i_msgty = 'E' i_msgno = '001'
i_msgv1 = 'Price must be greater than zero'
i_fieldname = ls_mod-fieldname
i_row_id    = ls_mod-row_id ).
ENDIF.
ENDLOOP.  " errors: protocol popup, cell stays red, table not updated
ENDMETHOD.

METHOD on_data_changed_finished.  " output table is already updated here
CHECK e_modified = abap_true.
LOOP AT et_good_cells INTO DATA(ls_cell).
INSERT ls_cell-row_id INTO TABLE mt_changed_rows.
ENDLOOP.
ENDMETHOD.

METHOD save.  " PAI, OK_CODE 'SAVE'
mo_grid->check_changed_data( IMPORTING e_valid = DATA(lv_valid) ).  " pending input
CHECK lv_valid = abap_true AND mt_changed_rows IS NOT INITIAL.
LOOP AT mt_changed_rows INTO DATA(lv_row).
DATA(ls_f) = mt_flights[ lv_row ].
UPDATE sflight SET price = @ls_f-price
WHERE carrid = @ls_f-carrid AND connid = @ls_f-connid AND fldate = @ls_f-fldate.
ENDLOOP.
COMMIT WORK.
CLEAR mt_changed_rows.
MESSAGE 'Prices saved' TYPE 'S'.
ENDMETHOD.
  • The attribute is MT_MOD_CELLS (LVC_T_MODI: ROW_ID, SUB_ROW_ID, FIELDNAME, VALUE, TABIX). Also: MT_GOOD_CELLS, MP_MOD_ROWS, MT_INSERTED_ROWS, MT_DELETED_ROWS.
  • In the handler use get_cell_value( ), modify_cell( ) (correct or derive a value), add_protocol_entry( ); display_protocol( ) shows the errors. Do not copy values into the table yourself, and never update the database inside DATA_CHANGED.
  • Save properly: lock with the enqueue FM when the user switches to edit mode (here ENQUEUE_ESFLIGHT), AUTHORITY-CHECK, validate, then UPDATE own tables – for SAP standard data use a BAPI or update function module, never a direct UPDATE.
  • Whole grid editable: layout EDIT = 'X'. Switch edit mode on / off: set_ready_for_input( 1 / 0 ). Per cell read-only: style MC_STYLE_DISABLED (5.2). Standard append / delete row buttons fill MT_INSERTED_ROWS / MT_DELETED_ROWS.
  • Own F4 help: register_f4_for_fields( VALUE #( ( fieldname = 'PRICE' register = 'X' ) ) ), handle ONF4, set er_event_data->m_event_handled = 'X'.

Part 7 – Containers, splitter, pictures, trees

7.1 Container types

Screen with a custom container, a 2 x 2 splitter and panes holding a tree, a picture, an editor and the grid; other container types beside it

Container

Use

CL_GUI_CUSTOM_CONTAINER

fills a custom control area drawn in the Screen Painter

CL_GUI_DOCKING_CONTAINER

docks to an edge of any screen (also selection screens) – no Screen Painter

CL_GUI_SPLITTER_CONTAINER

splits a parent container into N × M panes (Example 1)

CL_GUI_EASY_SPLITTER_CONTAINER

simple split into 2 panes

CL_GUI_DIALOGBOX_CONTAINER

own movable popup window

cl_gui_container=>default_screen

the whole screen area

  • Splitter: each pane is a container returned by get_container( row = … column = … ); size with set_row_height( ) / set_column_width( ). A pane can hold any control: grid, tree, picture, HTML viewer, text editor, dynamic document.

7.2 Picture in a container

  • Step 1: upload with SMW0 → "Binary data for WebRFC applications" → Find → Execute → Create → object name (e.g. ZALV_DEMO_LOGO) + description → Import file. Old but still works.
DATA lv_url TYPE cndp_url.                " type group CNDP
CALL FUNCTION 'DP_PUBLISH_WWW_URL'
EXPORTING  objid    = 'ZALV_DEMO_LOGO'  " SMW0 object
lifetime = cndp_lifetime_transaction
IMPORTING  url      = lv_url
EXCEPTIONS OTHERS   = 1.
DATA(lo_picture) = NEW cl_gui_picture( parent = mo_top ).  " e.g. a splitter pane
lo_picture->load_picture_from_url( url = lv_url ).
lo_picture->set_display_mode( cl_gui_picture=>display_mode_fit ).

7.3 Trees: simple tree control vs ALV tree

The simple "tree control" is CL_GUI_SIMPLE_TREE – a plain tree of nodes (folders or leaves), not an ALV tree. ALV trees with columns are CL_GUI_ALV_TREE and CL_SALV_TREE.

" node structure: SAP demo ABDEMONODE, or own DDIC structure = INCLUDE TREEV_NODE + field TEXT
DATA lt_nodes TYPE STANDARD TABLE OF abdemonode WITH EMPTY KEY.
mo_tree = NEW cl_gui_simple_tree(
parent              = mo_left  " e.g. left splitter pane
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single ).
lt_nodes = VALUE #(
( node_key = 'ROOT' isfolder = abap_true expander = abap_true text = 'Customers' )
( node_key = 'C1' relatkey = 'ROOT' relatship = cl_gui_simple_tree=>relat_last_child
text = 'Customer 1' )
( node_key = 'C2' relatkey = 'ROOT' relatship = cl_gui_simple_tree=>relat_last_child
text = 'Customer 2' ) ).
mo_tree->add_nodes( table_structure_name = 'ABDEMONODE' node_table = lt_nodes ).
" tree events must be registered; APPL_EVENT = space: handler runs at once (system event),
" 'X': PAI runs first, handler is called by cl_gui_cfw=>dispatch( ) (application event)
mo_tree->set_registered_events( events = VALUE #(
( eventid = cl_gui_simple_tree=>eventid_node_double_click appl_event = space ) ) ).
SET HANDLER on_node_double_click FOR mo_tree.
" METHODS on_node_double_click FOR EVENT node_double_click OF cl_gui_simple_tree
"   IMPORTING node_key.
  • Node fields: NODE_KEY, RELATKEY, RELATSHIP, ISFOLDER, EXPANDER, N_IMAGE, EXP_IMAGE, TEXT. ADD_NODES needs the DDIC structure name and the node table.

CL_GUI_SIMPLE_TREE event

Fires when

Needs

NODE_DOUBLE_CLICK

double click on a node

set_registered_events

NODE_CONTEXT_MENU_REQUEST

right click – fill the context menu

set_registered_events

NODE_CONTEXT_MENU_SELECT

user picks a context menu entry

follows a registered _REQUEST

NODE_KEYPRESS

registered key pressed on a node

set_registered_events + add_key_stroke( KEY_… )

EXPAND_NO_CHILDREN, SELECTION_CHANGED

expand empty folder (load children late) / selection changed

set_registered_events

  • Event ids for SET_REGISTERED_EVENTS are constants EVENTID_…; the table type is CNTL_SIMPLE_EVENTS (EVENTID, APPL_EVENT).
  • CL_GUI_ALV_TREE: pass an empty global output table to set_table_for_first_display( is_hierarchy_header = … ), then build nodes with add_node( i_relat_node_key = … i_relationship = cl_gui_column_tree=>relat_last_child i_node_text = … is_outtab_line = … IMPORTING e_new_node_key = … ) and finish with frontend_update( ). Events: NODE_DOUBLE_CLICK, ITEM_DOUBLE_CLICK, LINK_CLICK, BUTTON_CLICK, CHECKBOX_CHANGE, EXPAND_NC, context menu events – registered with set_registered_events( ); toolbar via get_toolbar_object( ).
  • CL_SALV_TREE: cl_salv_tree=>factory( IMPORTING r_salv_tree = … CHANGING t_table = <empty table> ), then get_nodes( )->add_node( related_node = … relationship = if_salv_c_node_relation=>last_child data_row = … text = … ), display( ). Events (CL_SALV_EVENTS_TREE): DOUBLE_CLICK, LINK_CLICK, CHECKBOX_CHANGE, EXPAND_EMPTY_FOLDER, KEYPRESS, ADDED_FUNCTION.

Part 8 – Example programs

Four grid programs in modern style (local class instead of FORMs, NEW, VALUE). Each uses the skeleton of 4.1 (screen 0100 with custom control 'CC_ALV', status S0100, PBO/PAI calling methods); only the parts that differ are shown. Adapt the selection ranges to your system's data.

Example 1 – ZALV_DEMO_SPLIT_TOP: splitter, TOP_OF_PAGE header, print events

Customers (KNA1) in the lower pane of a 2-row splitter, a dynamic-document header in the upper pane. The grid never raises TOP_OF_PAGE on screen by itself: list_processing_events( ) raises it for the given CL_DD_DOCUMENT.

" --- definition (PRIVATE SECTION); mt_customers: KUNNR, LAND1, NAME1 of KNA1
DATA mo_top TYPE REF TO cl_gui_container.  " upper splitter pane
METHODS: on_top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid IMPORTING e_dyndoc_id,
on_print_top_of_page FOR EVENT print_top_of_page OF cl_gui_alv_grid,
on_print_end_of_list FOR EVENT print_end_of_list OF cl_gui_alv_grid.

METHOD pbo.
CHECK mo_grid IS NOT BOUND.
mo_container = NEW #( container_name = 'CC_ALV' ).
DATA(lo_split) = NEW cl_gui_splitter_container( parent = mo_container rows = 2 columns = 1 ).
lo_split->set_row_height( id = 1 height = 25 ).  " % of the height (relative mode)
mo_top  = lo_split->get_container( row = 1 column = 1 ).
mo_grid = NEW #( i_parent = lo_split->get_container( row = 2 column = 1 ) ).
DATA(lt_fcat) = VALUE lvc_t_fcat( ( fieldname = 'KUNNR' ref_table = 'KNA1' )
( fieldname = 'LAND1' ref_table = 'KNA1' )
( fieldname = 'NAME1' ref_table = 'KNA1' ) ).
SET HANDLER on_top_of_page on_print_top_of_page on_print_end_of_list FOR mo_grid.
mo_grid->set_table_for_first_display( CHANGING it_outtab       = mt_customers
it_fieldcatalog = lt_fcat ).
DATA(lo_doc) = NEW cl_dd_document( style = 'ALV_GRID' ).
lo_doc->initialize_document( ).
mo_grid->list_processing_events( i_event_name = 'TOP_OF_PAGE' i_dyndoc_id = lo_doc ).
ENDMETHOD.

METHOD on_top_of_page.
e_dyndoc_id->add_text( text = 'Customer list' sap_style = cl_dd_document=>heading ).
e_dyndoc_id->new_line( ).
e_dyndoc_id->add_text( text = |{ lines( mt_customers ) } customers|
sap_color = cl_dd_document=>list_positive
sap_emphasis = cl_dd_document=>strong ).
e_dyndoc_id->add_gap( width = 2 ).
e_dyndoc_id->add_text( text = |Run on { sy-datum DATE = USER }|
sap_color = cl_dd_document=>list_total_int ).
e_dyndoc_id->merge_document( ).
e_dyndoc_id->display_document( parent = mo_top ).  " header into the upper pane
ENDMETHOD.

METHOD on_print_top_of_page.  " list / spool output only
WRITE: / 'Customer list', 'Page', sy-pagno.
ENDMETHOD.

METHOD on_print_end_of_list.
DATA(lv_count) = lines( mt_customers ).
WRITE: / lv_count, 'customers printed'.
ENDMETHOD.
  • Points to note: CALL METHOD … DISPLAY_DOCUMENT must not be swallowed by a comment line (otherwise the header is never shown); STRONG is an emphasis (sap_emphasis), not a size – sap_fontsize takes LARGE / MEDIUM / SMALL.
  • Test the print events: press Print in the grid → the output is created as a spool request → view it in SP01 (own requests: SP02). PRINT_TOP_OF_LIST / PRINT_END_OF_PAGE work the same way.
  • Simpler today: SALV set_top_of_list( ) with CL_SALV_FORM_LAYOUT_GRID (Part 3).

Example 2 – ZALV_DEMO_GRANDTOTAL: grand total with own text

Sales orders (VBAK) with a total line that shows "Total Net Value" instead of the default. Trick: a hidden column TOTTEXT is never filled, so all rows form one subtotal group; that subtotal line acts as the grand total and is labelled with the hidden column's heading, while NO_TOTLINE suppresses the real total line.

TYPES: BEGIN OF ty_order,
vbeln   TYPE vbak-vbeln,
erdat   TYPE vbak-erdat,
erzet   TYPE vbak-erzet,
ernam   TYPE vbak-ernam,
netwr   TYPE vbak-netwr,
waerk   TYPE vbak-waerk,
tottext TYPE c LENGTH 20,  " always empty -> one group for all rows
END OF ty_order.

METHOD build_fcat.
rt_fcat = VALUE #(
( col_pos = 1 fieldname = 'VBELN' coltext = 'Sales Doc' )
( col_pos = 2 fieldname = 'ERDAT' coltext = 'Date'       outputlen = 12 )
( col_pos = 3 fieldname = 'ERZET' coltext = 'Time'       outputlen = 12 )
( col_pos = 4 fieldname = 'ERNAM' coltext = 'Created By' outputlen = 22 )
( col_pos = 5 fieldname = 'NETWR' coltext = 'Net Value'  outputlen = 15
do_sum = abap_true cfieldname = 'WAERK' )
( col_pos = 6 fieldname = 'WAERK' coltext = 'Curr.' )
( fieldname = 'TOTTEXT' coltext = 'Total Net Value' no_out = abap_true ) ).
ENDMETHOD.

" in pbo:
DATA(lt_fcat) = build_fcat( ).
DATA(lt_sort) = VALUE lvc_t_sort( ( spos = 1 fieldname = 'TOTTEXT' subtot = abap_true ) ).
mo_grid->set_table_for_first_display(
EXPORTING is_layout       = VALUE #( no_totline = abap_true )  " hide the real total line
CHANGING  it_outtab       = mt_orders                          " CHANGING needs variables,
it_fieldcatalog = lt_fcat                            " not VALUE expressions
it_sort         = lt_sort ).
  • Points to note: ENDFORM must not end up inside a comment (… "Suppress output total line ENDFORM.); TOTTEXT is CHAR instead of STRING (safer for sort / subtotal columns); with CFIELDNAME the totals are per currency.

Example 3 – ZALV_DEMO_SUBTOTAL: subtotals with own text (event SUBTOTAL_TEXT)

Order items (VBAP: VBELN, POSNR, MATNR, NETWR) with a subtotal per order and the grand total. The handler replaces the default subtotal text.

" --- definition (PRIVATE SECTION)
METHODS on_subtotal_text FOR EVENT subtotal_text OF cl_gui_alv_grid
IMPORTING es_subtottxt_info ep_subtot_line e_event_data.

" --- in pbo; fcat: VBELN, POSNR 'Item No', MATNR 'Material', NETWR do_sum = 'X'
DATA(lt_sort) = VALUE lvc_t_sort( ( spos = 1 fieldname = 'VBELN' up = abap_true
subtot = abap_true ) ).
SET HANDLER on_subtotal_text FOR mo_grid.
" … set_table_for_first_display( … it_sort = lt_sort ) – grand total line stays on

" --- implementation
METHOD on_subtotal_text.
FIELD-SYMBOLS <lv_text> TYPE any.
ASSIGN e_event_data->m_data->* TO <lv_text>.             " text cell of the subtotal line
IF sy-subrc = 0.
<lv_text> = SWITCH string( es_subtottxt_info-criteria  " sort field of this level
WHEN 'VBELN' THEN 'Order subtotal'
ELSE 'Subtotal' ).
e_event_data->m_event_handled = abap_true.
ENDIF.
ENDMETHOD.
  • Check es_subtottxt_info-criteria to label each level (otherwise every level gets the same text); do not add an extra hidden TTEXT sort column (it only produces a second, duplicate subtotal line per order). EP_SUBTOT_LINE references the subtotal row if you need its values.

Example 4 – ZALV_DEMO_VARIANT: save and load layouts (delta of Example 2)

Identical to Example 2 except the display call:

mo_grid->set_table_for_first_display(
EXPORTING is_layout  = VALUE #( no_totline = abap_true )
is_variant = VALUE #( report = sy-repid )  " key of the saved layouts
i_save     = 'A'                           " global + user-specific layouts
i_default  = abap_true                     " a layout may be marked as default
CHANGING  it_outtab = mt_orders  it_fieldcatalog = lt_fcat  it_sort = lt_sort ).
  • Test: right-click column ERZET → Hide → Layout icon → Save layout → name /V1 → Continue. Sort VBELN descending → save as /V2. Next run: Layout icon → choose a layout from the list.
  • Names with '/' are global (cross-user) layouts – the only kind I_SAVE = 'X' allows. username = sy-uname in DISVARIANT is unnecessary.

Part 9 – Interview questions

REUSE_ALV_GRID_DISPLAY vs CL_GUI_ALV_GRID vs CL_SALV_TABLE?

REUSE FMs are legacy: SLIS catalog, events as callback FORMs, full screen only, not released for ABAP Cloud. CL_GUI_ALV_GRID is the OO grid control: needs a container, LVC catalog, many events, the only supported editable ALV. CL_SALV_TABLE is the simple OO model: factory( ) builds the catalog, full screen or container, runs in background, read-only.

What is a field catalog and how can you build it?

An internal table with one row per column (SLIS_T_FIELDCAT_ALV or LVC_T_FCAT): field name, heading, position, output length, colour, DO_SUM, HOTSPOT, EDIT, NO_OUT. Built automatically (I_STRUCTURE_NAME), with REUSE_ALV_ / LVC_FIELDCATALOG_MERGE from a DDIC structure, manually, or derived from SALV with cl_salv_controller_metadata=>get_lvc_fieldcatalog( ). Without it the ALV aborts.

What are the steps to display a CL_GUI_ALV_GRID?

Screen with a custom control area → in PBO create CL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID once (IS NOT BOUND) → read data, build field catalog and layout, SET HANDLER → set_table_for_first_display( ) → later refresh_table_display( ); PAI handles OK_CODE and Back.

How do you colour a row, a cell and a column?

Column: fcat EMPHASIZE 'Cxyz'. Row: CHAR4 field with the colour code + layout INFO_FNAME. Cell: LVC_T_SCOL field (FNAME + COLOR) + layout CTAB_FNAME. In SALV: set_color( ) for a column and set_color_column( ) with an LVC_T_SCOL field for rows and cells.

How do you make an ALV editable and save the changes?

Use CL_GUI_ALV_GRID; fcat EDIT = 'X' (or layout EDIT). Handle DATA_CHANGED to validate (MT_MOD_CELLS, get_cell_value, add_protocol_entry), optionally register_edit_event( mc_evt_enter / mc_evt_modified ). On SAVE in PAI call check_changed_data( ), lock, check authority and update via own UPDATE or a BAPI, then COMMIT WORK.

MC_EVT_ENTER vs MC_EVT_MODIFIED?

Both are extra triggers for DATA_CHANGED, registered with register_edit_event( ). MC_EVT_ENTER fires on Enter; MC_EVT_MODIFIED fires as soon as the user leaves a modified cell. Without either, DATA_CHANGED fires only on the Check button, toolbar functions or check_changed_data( ).

How do you add your own button to the grid toolbar?

Handle event TOOLBAR and append a line to e_object->mt_toolbar (FUNCTION, ICON, TEXT, BUTN_TYPE); register the handler before the first display or call set_toolbar_interactive( ). The click arrives in USER_COMMAND (E_UCOMM). Hide standard buttons with IT_TOOLBAR_EXCLUDING (MC_FC_… constants).

HOTSPOT_CLICK vs DOUBLE_CLICK vs BUTTON_CLICK?

HOTSPOT_CLICK: single click on a cell of a column with fcat HOTSPOT (E_ROW_ID, E_COLUMN_ID). DOUBLE_CLICK: double click on any cell (E_ROW, E_COLUMN). BUTTON_CLICK: click on a cell with style MC_STYLE_BUTTON (ES_COL_ID, ES_ROW_NO). In REUSE FMs both clicks come as USER_COMMAND '&IC1'.

How do users save layouts, and what does I_SAVE mean?

Pass IS_VARIANT with REPORT = sy-repid and I_SAVE: space none, 'X' global only (names start with '/'), 'U' user-specific only, 'A' both; I_DEFAULT = 'X' allows a default layout. A selection-screen parameter with F4 LVC_VARIANT_F4 lets users choose the start layout.

How do you show a header (top of page) in each ALV type?

REUSE: TOP_OF_PAGE FORM calling REUSE_ALV_COMMENTARY_WRITE (logo from OAER via I_LOGO). Grid: event TOP_OF_PAGE with a CL_DD_DOCUMENT, raised by list_processing_events( ), displayed in a splitter pane. SALV: set_top_of_list( ) with CL_SALV_FORM_LAYOUT_GRID.

Can CL_SALV_TABLE be editable, and what are its limits?

No supported edit mode – use CL_GUI_ALV_GRID. Other limits (SAP Help): 90 columns, 128 characters per column, 9 sort / subtotal levels, flat tables only, no background mode in a container. It can colour rows and cells, show traffic lights, hotspots and buttons.

Why ALV with IDA, and why still SAP GUI ALV in S/4HANA?

IDA reads only the visible rows and lets HANA sort, filter and total – no internal table, so millions of rows display fast (ABAP on HANA › 04). New end-user apps should be Fiori elements on CDS + RAP; SAP GUI ALV stays fine for back-office and brownfield reports in classic ABAP (on-premise, private cloud), using CL_SALV_TABLE / IDA instead of REUSE FMs.

Which ALV can you use in ABAP Cloud?

None. REUSE FMs, CL_GUI_ALV_GRID, CL_SALV_TABLE and CL_SALV_GUI_TABLE_IDA are classic ABAP only: ABAP for Cloud Development has no SAP GUI, no dynpros or lists, no executable programs and only released APIs. A list for the user is a Fiori elements list report on a CDS view entity with @UI annotations, exposed by a service definition and an OData V4 UI service binding; changes go through a RAP business object.

How do you show a table or CDS view with ALV with IDA?

cl_salv_gui_table_ida=>create( iv_table_name = 'SFLIGHT' )->fullscreen( )->display( ) for a table or DDIC view, create_for_cds_view( iv_cds_view_name = … ) for a CDS view (set_view_parameters( ) for CDS parameters). Select-options become named ranges via CL_SALV_RANGE_TAB_COLLECTOR and set_select_options( ), so filtering runs in the database. It is display-only and runs in dialog only.

How would you rebuild a classic ALV report the clean-core way?

SELECT → CDS view entity on released views; selection screen → filter bar (@UI.selectionField); field catalog → @UI.lineItem; layouts, sorting and export are built into the list report; authority check → CDS access control; editable grid → RAP BO. If the list needs ABAP logic, use a custom entity with a query provider class (Clean Core › 02 Clean-Core Report).

🏠 Start Here · ◀ 03 · Exceptions & Events · 05 · Interview Questions ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP