Section 9 of 11

ALV Reports

What ALV gives you for free, the three implementation styles, and how to build and adjust a field catalog.

Open contents

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

ApproachEntry pointCharacterRecommended?
Function moduleREUSE_ALV_GRID_DISPLAYClassic, verboseLegacy
CL_GUI_ALV_GRIDControl basedFine control, more codeFor complex needs
CL_SALV_TABLESALVConcise, covers most needsYes

A minimal SALV report

Displaying a table
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

Columns, totals and sorting
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

Key field catalog fields
FieldMeaning
FIELDNAMEThe internal table field
SELTEXT_L / M / SColumn headings
OUTPUTLENDisplay width
NO_OUTHidden initially but available to the user
DO_SUMTotal this column
HOTSPOTMake it clickable
REF_TABLE / REF_FIELDThe Dictionary definition to inherit from

๐Ÿ“– Unfamiliar term? Look it up in the SAP glossary.

Check your understanding

Test what you just read.

Quiz 1

What does ALV stand for?

Quiz 2

ALV allows users to freely customize column order and filters.

Quiz 3

What is the mechanism called that defines ALV display columns?

Quiz 4

Which class is recommended for ALV output in new development?

Quiz 5

REUSE_ALV_GRID_DISPLAY is a class-based ALV implementation.

Quiz 6

Arrange the implementation steps for displaying ALV using CL_SALV_TABLE.

Click items in the correct order