ERPClimb logoERPClimb

Code examples · Modern ABAP · Intermediate

ABAP report with ALV (CL_SALV_TABLE): optimized columns and a clickable order id

The problem

Sales needs a quick list of orders with a total.

How we solve it

  1. 1Local classdata + method
  2. 2Create and configure ALVfactory, columns, hotspot
  3. 3Click eventhandler

The result

A grid report with striped rows, optimized column widths and a clickable order id that opens an information message with that order.

Overview drawn by ERPClimb from this example. The steps are the same as in the code below.

1. The requirement

Sales needs a quick list of orders with a total. Users must be able to sort, filter and export it like any SAP list, and clicking an order id must show details of that order.

2. How we design it

Do not draw a list by hand. Hand the internal table to the standard ALV class, which gives sorting, filtering, export and layout saving for free. Configure the look through the column and display objects, and attach one event handler for the click. Keep the data in one place (a table in the class) and the screen code in another.

Why we decided it this way

  1. 1CL_SALV_TABLE and not WRITEThe user gets the standard list functions without extra code.
  2. 2A local class with an event handlerALV tells us about clicks through events, and handlers must be methods.
  3. 3Hotspot on the id columnA clickable key is the standard way to navigate to details.
  4. 4Exceptions caught around the ALV callsColumn names and factory calls can raise exceptions; an uncaught one ends in a short dump.

Before you start

  • An on-premise ABAP system or trial and SAP GUI or ADT with GUI support. Create a report in package $TMP for the test.

3. The code, step by step

Step 1 of 3: Declare the class and the data

A row type, a table, the run method and the click handler method.

ABAP · Report ZDEMO_SALV_ORDERS
" Class definition
REPORT zdemo_salv_orders.

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    TYPES: BEGIN OF ty_row,
             order_id TYPE c LENGTH 10,
             customer TYPE c LENGTH 20,
             amount   TYPE p LENGTH 8 DECIMALS 2,
           END OF ty_row,
           tt_row TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY.
    METHODS run.
  PRIVATE SECTION.
    DATA rows TYPE tt_row.
    METHODS on_link_click
      FOR EVENT link_click OF cl_salv_events_table
      IMPORTING row column.
ENDCLASS.
Part by part (plain text)
  1. Class definition. ty_row describes one list line. The table of rows is private data. run builds and shows the list. on_link_click is the handler for the click event of the ALV; its parameters row and column say which cell was clicked.

Open in the portal

The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.

4. The final outcome

A grid report with striped rows, optimized column widths and a clickable order id that opens an information message with that order.

What you should see

Run the report: a grid with four orders appears with standard toolbar functions. Click an order id: the message 'Order 1002 clicked' appears.

Try it and check the result

  • Create the report, activate it and run with F8.
  • The grid must show four rows with a toolbar. Sort by amount through the column menu.
  • Click an order id: an information message names that order.
  • Rename the string 'ORDER_ID' to 'ORDER' on purpose and run again: the error message from the CATCH block appears instead of a dump.

Common mistakes

  • Column names passed to get_column must be the technical field names in capital letters.
  • The event handler must be registered after the ALV object exists and before display( ).
  • ROW is the index of the line in your internal table, also when the user sorted or filtered the grid, so READ TABLE ... INDEX row is safe as long as you do not change the table while the list is shown.
  • CL_SALV_TABLE is for on-premise or classic development. In ABAP Cloud use Fiori elements through RAP instead.

Keep learning

Checking status: Reviewed line by line against SAP documentation. Not executed on a live system. Reviewed 2026-11-25. Release: ABAP on SAP NetWeaver / S/4HANA on-premise with SAP GUI. CL_SALV_TABLE is not available in ABAP Cloud development.

Original ERPClimb teaching code with illustrative names. Not taken from a customer system. Syntax can differ by release; check the references below and activate in a sandbox first. ERPClimb is independent of SAP SE.