ALV (ABAP List Viewer) displays internal tables as tables. Any reporting in ABAP will use it.
What you get without writing it
- Column sorting, filtering, rearranging and resizing
- Automatic subtotals and totals
- Export to Excel, CSV and PDF
- Saved display layouts (variants)
- Row selection and double-click navigation
- Print layout
Three implementations
| Approach | Entry point | Character | Recommended? |
|---|---|---|---|
| Function module | REUSE_ALV_GRID_DISPLAY | Classic, verbose | Legacy |
| CL_GUI_ALV_GRID | Control based | Fine control, more code | For complex needs |
| CL_SALV_TABLE | SALV | Concise, covers most needs | Yes |
A minimal SALV report
DATA lo_alv TYPE REF TO cl_salv_table.
SELECT matnr, mtart, meins FROM mara
INTO TABLE @DATA(lt_mara) UP TO 100 ROWS.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_mara ).
lo_alv->get_functions( )->set_all( abap_true ).
lo_alv->get_columns( )->set_optimize( abap_true ).
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_msg).
MESSAGE lx_msg->get_text( ) TYPE 'E'.
ENDTRY.Adjusting the display
DATA(lo_columns) = lo_alv->get_columns( ).
lo_columns->get_column( 'MANDT' )->set_visible( abap_false ).
DATA(lo_agg) = lo_alv->get_aggregations( ).
lo_agg->add_aggregation( columnname = 'MENGE'
aggregation = if_salv_c_aggregation=>total ).
DATA(lo_sorts) = lo_alv->get_sorts( ).
lo_sorts->add_sort( columnname = 'MATNR'
sequence = if_salv_c_sort=>sort_up ).Field catalogs
| Field | Meaning |
|---|---|
| FIELDNAME | The internal table field |
| SELTEXT_L / M / S | Column headings |
| OUTPUTLEN | Display width |
| NO_OUT | Hidden initially but available to the user |
| DO_SUM | Total this column |
| HOTSPOT | Make it clickable |
| REF_TABLE / REF_FIELD | The Dictionary definition to inherit from |