Your First ALV Report (Program 1)
1. Why ALV? (And why WRITE is not enough)
ALV stands for ABAP List Viewer. It shows your internal table as an interactive grid. With WRITE you only get plain text. With ALV the user gets, for free:
- Sorting by any column
- Filtering and searching
- Totals and subtotals
- Moving, hiding and resizing columns
- Export to Excel or PDF
- Saving personal layouts
Nearly every report in a real project ends in ALV, so this is the most useful step in the series.
2. Two ways to build ALV
| Approach | Style | Notes |
|---|---|---|
REUSE_ALV_GRID_DISPLAY | Function module | Simple, very common in existing code. Used in this series first. |
CL_SALV_TABLE | Object-oriented | SAP’s recommended choice for new read-only ALV. Covered in Blog 15. |
CL_GUI_ALV_GRID | Object-oriented | Most control, including editable cells. More code. |
You will meet REUSE_ALV_GRID_DISPLAY in a huge amount of existing code, so learning it first helps you read what others wrote.
3. The two building blocks
Every ALV needs exactly two things:
| Block | What it is | In Program 1 |
|---|---|---|
| Output table | The internal table with the data to show | lt_vbak |
| Field catalog | A description of each column: name, heading, length, format | Built automatically from structure ZST_VBAK |
If you pass a dictionary structure name, ALV builds the field catalog for you. This blog uses that. Blog 6 builds the catalog by hand when you need full control.
4. Create the ZST_VBAK structure (SE11)
The structure tells ALV which columns exist and what to call them.
- Open
SE11, select Data type, enterZST_VBAK, and click Create. - Choose Structure and enter a short description, for example Sales order header for ALV.
- On the Components tab, add these rows. Use the same name for the component and the data element.
- Open the Currency/Quantity Fields tab. For
NETWR, enter reference tableZST_VBAKand reference fieldWAERK. - Choose Extras > Enhancement Category and pick Can be enhanced (character-type or numeric), or whatever your team uses.
- Save and activate with Ctrl+F3.
| Component | Data element | Meaning |
|---|---|---|
VBELN | VBELN | Sales document number |
ERDAT | ERDAT | Created on |
ERNAM | ERNAM | Created by |
VBTYP | VBTYP | Document category |
NETWR | NETWR | Net value |
WAERK | WAERK | Document currency |
A currency amount needs to know its currency to display correctly. Without the reference in step 4, the structure will not activate.
5. Program 1: full code
*&---------------------------------------------------------------------*
*& Report ZALV_PROGRAM1
*& First ALV report: automatic field catalog from a DDIC structure
*&---------------------------------------------------------------------*
REPORT zalv_program1.
*---------------------------------------------------------------------*
* Data declarations
*---------------------------------------------------------------------*
DATA lt_vbak TYPE STANDARD TABLE OF zst_vbak WITH DEFAULT KEY.
DATA lv_erdat TYPE vbak-erdat.
DATA lv_repid TYPE sy-repid.
*---------------------------------------------------------------------*
* Selection screen
*---------------------------------------------------------------------*
SELECT-OPTIONS s_erdat FOR lv_erdat.
PARAMETERS p_max TYPE i DEFAULT 500.
INITIALIZATION.
s_erdat-sign = 'I'.
s_erdat-option = 'BT'.
s_erdat-low = sy-datum - 30.
s_erdat-high = sy-datum.
APPEND s_erdat.
*---------------------------------------------------------------------*
* Main logic
*---------------------------------------------------------------------*
START-OF-SELECTION.
" 1. Read data
SELECT vbeln, erdat, ernam, vbtyp, netwr, waerk
FROM vbak
WHERE erdat IN @s_erdat
ORDER BY erdat DESCENDING, vbeln
INTO CORRESPONDING FIELDS OF TABLE @lt_vbak
UP TO @p_max ROWS.
IF sy-subrc <> 0.
MESSAGE 'No sales orders found for your selection'
TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
" 2. Show data in ALV (field catalog built automatically)
lv_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_repid
i_structure_name = 'ZST_VBAK'
TABLES
t_outtab = lt_vbak
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'ALV could not be displayed' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
6. Walkthrough
| Part | What it does |
|---|---|
TYPE STANDARD TABLE OF zst_vbak | The output table has exactly the columns of the structure. |
s_erdat, p_max | The user picks the date range and the maximum rows (Blog 2). |
INITIALIZATION | Pre-fills the last 30 days. |
SELECT ... INTO CORRESPONDING FIELDS OF TABLE | Fills only the columns that exist in both the query and the table. |
IF sy-subrc <> 0 | Stops with a clear message if nothing was found (Blog 3). |
lv_repid = sy-repid | Stores the program name in a variable first. This is safer than passing sy-repid directly. |
i_callback_program | Tells ALV which program it belongs to. |
i_structure_name | The magic line. ALV reads the structure and builds the field catalog by itself. |
TABLES t_outtab | The internal table to display. |
EXCEPTIONS | Handles a failure of the function module. |
From the data elements in the structure. Their short, medium and long texts become the column headings, so a clean data element gives you good headings for free.
7. What the user sees
When you run the report, press F8 on the selection screen. A grid like this appears (values will differ):
| Sales Doc. | Created on | Created by | Cat. | Net value | Curr. |
|---|---|---|---|---|---|
| 0000004971 | 30.10.2026 | SALES01 | C | 12,500.00 | INR |
| 0000004970 | 28.10.2026 | SALES02 | C | 8,200.00 | INR |
| 0000004969 | 25.10.2026 | SALES01 | A | 1,450.00 | INR |
The toolbar above the grid comes automatically. Try these:
- Click a column header, then the sort icons.
- Select a column and use the filter icon.
- Select Net value and click the sum icon.
- Use Export > Spreadsheet to open the data in Excel.
- Use Settings > Layout to hide or reorder columns.
8. The same report with SALV
To give you a preview of the modern approach, here is the display part using CL_SALV_TABLE. It needs no structure name because it reads the table’s own type.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(lo_alv)
CHANGING t_table = lt_vbak ).
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 'S' DISPLAY LIKE 'E'.
ENDTRY.
Both give a similar grid. Blog 15 compares them in depth.
9. Try it yourself
- Add a new field
VKORGtoZST_VBAK, add it to theSELECT, and see the new column. - Add a selection screen field for sales organization (
s_vkorg) and use it inWHERE. - Change
ORDER BYto sort bynetwr DESCENDING. - In the ALV, sort by Created by, then save a layout.
- Export the grid to Excel and compare it with what you see on screen.
10. Common mistakes
- Structure not activated. The program fails or shows no columns. Activate it in SE11.
- No currency reference for
NETWR, so the structure will not activate. - Structure name in lowercase or misspelled. Use the exact name in capitals:
'ZST_VBAK'. - Table does not match the structure. Declare the output table
TYPE ... OF zst_vbak. - Forgetting
TABLES t_outtab. ALV has nothing to show. - No
sy-subrccheck afterSELECT. The user sees an empty grid with no explanation. - Skipping
i_callback_program. Later features such as user commands will not work. - Reading millions of rows. Use
WHEREandUP TO n ROWSwhile testing.
Up next: Blog 6
Manual Field Catalog and Report Events. Take full control of column names, widths and positions, and add a header to your ALV.
WhatsApp us