# ABAP ALV Report Skeleton Generator

> Source: https://netray.co/tools/abap-alv-report-skeleton-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Enter a program name, table and selection field and get a working ABAP report that shows an ALV grid using CL_SALV_TABLE.

## Category

sap

## Erp

SAP ECC / S/4HANA

## Audience

- ABAP developer
- SAP technical consultant

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Program name

**Key:** program

**Type:** text

**Default:** zr_open_orders

#### Database table

**Key:** table

**Type:** text

**Default:** vbak

#### Fields (comma separated)

**Key:** fields

**Type:** text

**Default:** vbeln, erdat, kunnr, netwr, waerk

#### Selection field

**Key:** sel_field

**Type:** text

**Default:** kunnr

#### ALV header text

**Key:** title

**Type:** text

**Default:** Sales orders by customer

**Blocks:**

#### Report source

**Body:** REPORT {{program}}.

DATA gs_sel TYPE {{table}}.
DATA gt_data TYPE STANDARD TABLE OF {{table}} WITH DEFAULT KEY.

SELECT-OPTIONS s_sel FOR gs_sel-{{sel_field}}.

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

FORM get_data.
  SELECT {{fields}}
    FROM {{table}}
    WHERE {{sel_field}} 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( '{{title}}' ).

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

**Notes:** 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use it

**Body:** 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

**Body:** 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

**Body:** 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

**Body:** 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.

**Cta:** 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.

**Faq:**

#### Should I use CL_SALV_TABLE or REUSE_ALV_GRID_DISPLAY?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

abap alv report example, cl_salv_table example, abap alv report template, abap simple alv program, cl_salv_table factory, abap report with selection screen and alv, abap salv set_optimize columns

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
