SAPFree generatorPDF, Excel, Word exportSAP ECC / S/4HANA

ABAP ALV Report Skeleton Generator

Nearly every ABAP developer starts a new report from the same pattern: selection screen, SELECT, ALV grid. This generator gives you that skeleton using CL_SALV_TABLE, the object-oriented ALV class that needs far less code than the older REUSE_ALV_GRID_DISPLAY function module.

Fill in

Generated code
Download:

Report source

REPORT zr_open_orders.

DATA gs_sel TYPE vbak.
DATA gt_data TYPE STANDARD TABLE OF vbak WITH DEFAULT KEY.

SELECT-OPTIONS s_sel FOR gs_sel-kunnr.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM show_alv.

FORM get_data.
  SELECT vbeln, erdat, kunnr, netwr, waerk
    FROM vbak
    WHERE kunnr IN @s_sel
    INTO CORRESPONDING FIELDS OF TABLE @gt_data.
  IF sy-subrc <> 0.
    MESSAGE 'No data found for the selection' TYPE 'S' DISPLAY LIKE 'W'.
  ENDIF.
ENDFORM.

FORM show_alv.
  DATA lo_alv TYPE REF TO cl_salv_table.
  CHECK gt_data IS NOT INITIAL.
  TRY.
      cl_salv_table=>factory(
        IMPORTING r_salv_table = lo_alv
        CHANGING  t_table      = gt_data ).

* standard toolbar: sort, filter, export, layouts
      lo_alv->get_functions( )->set_all( abap_true ).

* optimal column width and zebra pattern
      lo_alv->get_columns( )->set_optimize( abap_true ).
      lo_alv->get_display_settings( )->set_striped_pattern( abap_true ).
      lo_alv->get_display_settings( )->set_list_header( 'Sales orders by customer' ).

      lo_alv->display( ).
    CATCH cx_salv_msg INTO DATA(lx_msg).
      MESSAGE lx_msg TYPE 'E'.
  ENDTRY.
ENDFORM.

This is the minimum viable ALV. Add column texts with get_columns( )->get_column( 'FIELDNAME' )->set_long_text( ), hotspots and double click handling with event handlers, and layout saving with get_layout( )->set_key( ). Add an authority check for the table before the SELECT. The inline syntax needs ABAP 7.40 or later.

Replace a stack of Z reports

Tell us which custom reports your users ask for most. We can describe what a grounded query layer would cover.

Optional. The tool and every export work without this. No spam.

How to use it

Enter the program name, the table you read, the field list and one field for the selection screen. The generated report declares a work area to anchor SELECT-OPTIONS, reads the data into an internal table, and shows it with CL_SALV_TABLE=>FACTORY. Paste it into SE38 or ADT, activate it and run it. From there, you extend the SELECT, add columns, rename headings and register event handlers for clicks.

What the SALV calls do

FACTORY builds the ALV object around your internal table. GET_FUNCTIONS( )->SET_ALL switches on the standard toolbar, which gives users sort, filter, subtotal, export to Excel and layout management without extra code. GET_COLUMNS( )->SET_OPTIMIZE adjusts column widths to content. GET_DISPLAY_SETTINGS controls the title and striped pattern. DISPLAY then renders the grid in full-screen. The CATCH on CX_SALV_MSG covers the factory call.

Making it production ready

Before release, move logic into a local class so it can be unit tested, add an authority check on the displayed data, restrict the SELECT with the selection screen to avoid reading millions of rows, and apply column texts and currency or unit references. Currency amount fields need their currency key column in the same table for correct display. Use the layout key so users can save variants. For very large data sets consider paging or a CDS-based report instead.

Common mistakes

Frequent problems are building the ALV before checking the table is filled, using SELECT * on wide tables, missing authority checks, mixing business logic into FORM routines that cannot be tested, and forgetting that SALV is for display, while editable grids still need CL_GUI_ALV_GRID. Also avoid hard coding column technical names in capitals with typos, because the lookup raises an exception when a name is wrong.

Frequently Asked Questions

Should I use CL_SALV_TABLE or REUSE_ALV_GRID_DISPLAY?

For new read-only reports, CL_SALV_TABLE is the simpler and more current choice. The function module still works and exists in a lot of legacy code, but it needs a field catalog and more lines for the same result.

Can CL_SALV_TABLE be editable?

Not in a general way. CL_SALV_TABLE is designed for display. If users must edit cells in the grid, use CL_GUI_ALV_GRID with a custom container, or build a SAP Fiori or UI5 app for modern requirements.

How do I add a double click or hotspot?

Get the events object with lo_alv->get_event( ), create a handler class with a method for the DOUBLE_CLICK or LINK_CLICK event and register it with SET HANDLER before calling display. For hotspots, set the column cell type to hotspot first.

Why do my amounts show without decimals or currency?

Currency amounts need a reference to a currency key field. Set the column currency column with set_currency_column( 'WAERK' ) or make sure the data element is linked in the DDIC. Without that, the display rule cannot format the value correctly.

If most of your custom reports are variations of the same question, we can discuss answering them directly from the ERP data with a read-only assistant.