Create ALV Reports in SAP ABAP: Interactive & Dynamic ALV

How to Create an ALV Report in SAP ABAP: Step-by-Step Tutorial with an Example
Table of Contents
- What Is ALV Report in SAP ABAP?
- ALV Full Form in SAP ABAP
- Types of ALV in SAP ABAP
- How to Create ALV Report in SAP ABAP
- ALV Grid Display in SAP ABAP
- ALV Report Events in SAP ABAP
- Interactive ALV Report in SAP ABAP
- OOPs ALV in SAP ABAP
- Hierarchical ALV Report in SAP ABAP
- Dynamic ALV in SAP ABAP
- How to Add Button in ALV Report in SAP ABAP
- How to Refresh ALV Grid Display in SAP ABAP
- ALV Report Example in SAP ABAP
- Conclusion
What Is ALV Report in SAP ABAP?
If you're in the process of learning SAP ABAP, understanding ALV reports within SAP ABAP is an essential skill that is not a matter of choice. The ALV (ABAP List Viewer) is SAP's built-in framework that displays tabular data in a dynamic grid format that is feature-rich. Before ALV was created, developers had to create custom logic to sort or filtering, tallying and exporting data — a time-consuming and error-prone procedure.
With ALV, you'll get all these features from the beginning:
- Sorting and filtering columns
- Totals of subtotals and the grand totals
- Export to Excel or PDF local file
- Print-ready layouts
- Reordering columns and concealing
- Interactive drill-down capabilities
ALV can be found in nearly every SAP module that includes FI (Finance) up to MM (Materials Management) to SD (Sales and Distribution). Understanding ALV within SAP ABAP can be one of the best capabilities you can learn when you become an ABAP developer.
ALV Full Form in SAP ABAP
The ALV full form that is available in SAP ABAP is the ABAP List Viewer. It is an industry-standard SAP tool that makes it easier to report-making process using lists by providing a uniform, strong output interface.
Incorporated into SAP R/3, ALV has changed significantly in the past:
| Generation | Technology | Description |
|---|---|---|
| Classic ALV | Function Modules (REUSE_ALV_*) | Procedural approach using FM calls |
| ALV Grid Control | CL_GUI_ALV_GRID | Object-oriented, embedded into SAP screens |
| OOPs ALV | CL_SALV_TABLE | Modern, fully OO-based and highly recommended |
Types of ALV in SAP ABAP
Before you dive into the code, it is helpful to know the fundamental varieties of ALV in SAP ABAP:
- Classic ALV (Function Module-based) — Uses standard function modules like REUSE_ALV_GRID_DISPLAY and REUSE_ALV_LIST_DISPLAY. It is simple to implement, but it is restricted in its flexibility.
- ALV Grid Control — Built in the SAP Control Framework using the class CL_GUI_ALV_GRID. This requires a custom-designed screen with an individual container. Offers deep customization.
- OOPs ALV (CL_SALV_TABLE) — The most recent method. Utilizes object-oriented ABAP and has minimum boilerplate. Ideal for developing new ideas.
- Hierarchical ALV — Displays information in a tree-like format, showing parent-child relations.
- Dynamic ALV — Field catalog is built during runtime, based on flexible data structure.
How to Create ALV Report in SAP ABAP
This is a top-level procedure to follow for creating ALV reports in SAP ABAP by using the traditional function module method:
Step 1: Define the Data Structure
TYPES: BEGIN OF ty_employee,
empid TYPE numc5,
empname TYPE char30,
dept TYPE char20,
salary TYPE p DECIMALS 2,
END OF ty_employee.
DATA: lt_employee TYPE TABLE OF ty_employee,
lw_employee TYPE ty_employee.
Step 2: Populate the Internal Table
lw_employee-empid = '00001'.
lw_employee-empname = 'John Doe'.
lw_employee-dept = 'Finance'.
lw_employee-salary = 75000.
APPEND lw_employee TO lt_employee.
lw_employee-empid = '00002'.
lw_employee-empname = 'Jane Smith'.
lw_employee-dept = 'HR'.
lw_employee-salary = 68000.
APPEND lw_employee TO lt_employee.
Step 3: Build the Field Catalog
DATA: lt_fcat TYPE slis_t_fieldcat_alv,
lw_fcat TYPE slis_fieldcat_alv.
lw_fcat-fieldname = 'EMPID'.
lw_fcat-seltext_m = 'Employee ID'.
lw_fcat-col_pos = 1.
APPEND lw_fcat TO lt_fcat.
lw_fcat-fieldname = 'EMPNAME'.
lw_fcat-seltext_m = 'Employee Name'.
lw_fcat-col_pos = 2.
APPEND lw_fcat TO lt_fcat.
Step 4: Call the ALV Function Module
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_structure_name = 'TY_EMPLOYEE'
it_fieldcat = lt_fcat
TABLES
t_outtab = lt_employee
EXCEPTIONS
program_error = 1
OTHERS = 2.
This four-step procedure addresses the fundamental question of how to build an ALV report using SAP ABAP.
ALV Grid Display in SAP ABAP
Grid display within SAP ABAP can be the most frequently employed display mode. It displays data in the form of a spreadsheet, and allows interactive features such as sorting, filters, resizing columns, and export.
To use grid display specifically (as opposed to list display), call REUSE_ALV_GRID_DISPLAY instead of REUSE_ALV_LIST_DISPLAY.
Important parameters you need to be aware of:
| Parameter | Purpose |
|---|---|
| I_CALLBACK_PROGRAM | The program name is for routines to call back. |
| I_CALLBACK_USER_COMMAND | Form routine to handle the actions of the toolbar |
| IT_FIELDCAT | Field catalog table defining columns |
| IS_LAYOUT | Layout settings (e.g., zebra stripes, edit mode) |
| IT_SORT | The default sort criteria |
| IT_FILTER | Default filter values |
Layout Customization Example
DATA: ls_layout TYPE slis_layout_alv.
ls_layout-zebra = 'X'. " Alternating row colors
ls_layout-colwidth_optimize = 'X'. " Auto-fit column widths
ls_layout-edit = ' '. " Non-editable grid
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
...
ALV Report Events in SAP ABAP
Understanding the ALV events that occur in SAP ABAP is crucial to create dynamic and feature-rich reports. Events let your program react to actions by users, such as pressing a button, choosing a row, or double-clicking on a cell.
Key Events in ALV Reports in SAP ABAP
| Event | Description |
|---|---|
| USER_COMMAND | It is activated when a user clicks the toolbar button |
| TOP_OF_PAGE | Fires occur before the page renders |
| END_OF_PAGE | Fires are lit at the conclusion of every page |
| TOP_OF_LIST | The fires are in the lead |
| END_OF_LIST | The fires are at the end of the list |
| CALLER_EXIT | This toolbar modification can be customized to suit your needs. |
Setting Up Events
DATA: lt_events TYPE slis_t_event,
lw_event TYPE slis_alv_event.
lw_event-name = slis_ev_user_command.
lw_event-form = 'USER_COMMAND'.
APPEND lw_event TO lt_events.
lw_event-name = slis_ev_top_of_page.
lw_event-form = 'TOP_OF_PAGE'.
APPEND lw_event TO lt_events.
Handling the USER_COMMAND Event
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'. " Standard double-click
MESSAGE 'Row selected: ' && rs_selfield-tabindex TYPE 'I'.
WHEN 'CUSTOM_BTN'.
" Customize the button logic here
ENDCASE.
ENDFORM.
Understanding the events that occur in ALV reports within SAP ABAP is what differentiates the simple list output from dynamic business applications.
Interactive ALV Report in SAP ABAP
An interactive ALV report in SAP ABAP lets users go deeper from an overview report to more detailed information by double-clicking rows, or choosing entries. This is among the most frequently requested features in SAP report generation.
How Interactive ALV Works
- First list provides summary data (e.g., department-wise sums)
- A row is double-clicked by the user.
- The USER_COMMAND event starts firing with &IC1
- The program retrieves the detail records and calls another ALV display
Example: Interactive Drill-Down
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lt_detail TYPE TABLE OF ty_employee_detail.
IF r_ucomm = '&IC1'.
" Get selected department
DATA(lv_dept) = <selected_row>-dept.
" Fetch detail records
SELECT * FROM zemployee_detail
INTO TABLE lt_detail
WHERE dept = lv_dept.
" Display detail ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
TABLES
t_outtab = lt_detail.
ENDIF.
ENDFORM.
This pattern is the foundation of interactive ALV reports within SAP ABAP creation.
OOPs ALV in SAP ABAP
OOPs ALV in SAP ABAP makes use of an ABAP class called CL_SALV_TABLE and is the most modern, recommended method for current ABAP development. It is simpler, more manageable, and uses significantly less code than the method of function modules.
Basic OOPs ALV Example
DATA: lo_salv TYPE REF TO cl_salv_table,
lo_columns TYPE REF TO cl_salv_columns_table,
lo_column TYPE REF TO cl_salv_column_table,
lo_display TYPE REF TO cl_salv_display_settings.
TRY.
" Create ALV instance
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_salv
CHANGING t_table = lt_employee ).
" Get columns object
lo_columns = lo_salv->get_columns( ).
lo_columns->set_optimize( abap_true ).
" Set column header
lo_column ?= lo_columns->get_column( 'EMPNAME' ).
lo_column->set_long_text( 'Employee Name' ).
" Configure display settings
lo_display = lo_salv->get_display_settings( ).
lo_display->set_striped_pattern( cl_salv_display_settings=>true ).
lo_display->set_list_header( 'Employee Report' ).
" Display
lo_salv->display( ).
CATCH cx_salv_msg INTO DATA(lx_msg).
MESSAGE lx_msg->get_text( ) TYPE 'E'.
ENDTRY.
Why Choose OOPs ALV?
- It is not necessary to create the field catalog manually
- Error handling based on exceptions
- Cleaner, easier to read code
- Support for the latest SAP features
- Easier unit testing
OOPs ALV for SAP ABAP is the future of ALV development. It is recommended for SAP S/4HANA and BTP ABAP environments.
Hierarchical ALV Report in SAP ABAP
A hierarchical ALV report within SAP ABAP (also called hierarchy ALV in SAP ABAP) displays information in a tree-like parent-child arrangement — perfect for charting orgs or BOM (Bill of Materials) data or any other master-detail connection.
This uses the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY.
Key Concepts
- Table Header — The parent-level information (e.g., Sales Orders)
- Table of Items — The data at the child level (e.g., Sales Order Line Items)
- Key fields — Fields that connect items and the header table
Example
DATA: lt_header TYPE TABLE OF ty_order_header,
lt_items TYPE TABLE OF ty_order_items,
ls_keyinfo TYPE slis_keyinfo_alv.
" Define key relationship
ls_keyinfo-header01 = 'VBELN'. " Header key field
ls_keyinfo-item01 = 'VBELN'. " Item key field
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
is_keyinfo = ls_keyinfo
it_fieldcat = lt_fcat
TABLES
t_outtab_head = lt_header
t_outtab_item = lt_items.
Hierarchical ALV reports in SAP ABAP are frequently used in the procurement, logistics, finance, and other modules in which summary-to-detail relationships are prevalent.
Dynamic ALV in SAP ABAP
Dynamic ALV in SAP ABAP refers to the creation of an ALV report in which the field catalog and columns are determined during runtime and not designed during design time. This is beneficial for situations where the columns displayed are determined by input from users or the configuration.
Approach Using Dynamic Internal Tables
DATA: lo_struct TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
lt_comp TYPE cl_abap_structdescr=>component_table,
lw_comp TYPE cl_abap_structdescr=>component,
lr_data TYPE REF TO data.
" Define components dynamically
lw_comp-name = 'FIELD1'.
lw_comp-type = cl_abap_elemdescr=>get_c( 20 ).
APPEND lw_comp TO lt_comp.
lw_comp-name = 'FIELD2'.
lw_comp-type = cl_abap_elemdescr=>get_i( ).
APPEND lw_comp TO lt_comp.
" Create dynamic structure
lo_struct = cl_abap_structdescr=>create( lt_comp ).
lo_table = cl_abap_tabledescr=>create( lo_struct ).
" Create data reference
CREATE DATA lr_data TYPE HANDLE lo_table.
Dynamic ALV within SAP ABAP is a cutting-edge technique that is commonly employed in reporting frameworks, configuration-driven tools as well as general display tools.
How to Add Button in ALV Report in SAP ABAP
Being aware of how to insert a button to reports using SAP ABAP allows you to expand the standard toolbar by adding your own custom actions — for example "Send Email", "Approve", or "Export to a Custom Format".
Steps to Add Custom Buttons
Step 1: Design a new PF-Status (GUI Status) in SE41 using your own custom function and button.
Step 2: Create the CALLER_EXIT event and then set the PF-Status programmatically.
" In events setup
lw_event-name = slis_ev_caller_exit_at_start.
lw_event-form = 'SET_PF_STATUS'.
APPEND lw_event TO lt_events.
Step 3: Set up the form routine
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZMY_STATUS' EXCLUDING rt_extab.
ENDFORM.
Step 4: Make sure you handle the mouse click in the USER_COMMAND
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN 'ZAPPROV'.
PERFORM approve_records.
WHEN 'ZEMAIL'.
PERFORM send_email.
ENDCASE.
ENDFORM.
This is the method you can use to implement the button to the ALV report within SAP ABAP — it's among the top requested customizations, and for good reason.
How to Refresh ALV Grid Display in SAP ABAP
If data is changed (e.g., following an action by a user) you must be aware of which refresh method to use in the ALV grid display within SAP ABAP without having to run the entire report completely from the beginning.
For ALV Grid Control (CL_GUI_ALV_GRID)
" Method 1: Soft refresh (keeps layout, updates data)
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable = VALUE lvc_s_stbl( row = 'X' col = 'X' ).
" Method 2: Hard refresh (full redraw)
CALL METHOD go_grid->refresh_table_display.
For OOPs ALV (CL_SALV_TABLE)
" Refresh the ALV display
lo_salv->refresh( ).
Important: Keep Reference to the ALV Object
For the purpose of refreshing your grid you need to keep the ALV object's reference in an attribute of class or global so that it can be accessed following your initial call to display.
DATA: go_salv TYPE REF TO cl_salv_table. " Global reference
Understanding the best way to update ALV grid displays within SAP ABAP is essential to create editable ALV reports, approval workflows, and the tools for monitoring in real time.
ALV Report Example in SAP ABAP
Here is a complete and working ALV report example from SAP ABAP with the OOPs ALV (CL_SALV_TABLE) that connects all the concepts:
REPORT zalv_oops_example.
" --- Data Declaration ---
TYPES: BEGIN OF ty_flight,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
fldate TYPE s_date,
price TYPE s_price,
currency TYPE s_currcode,
END OF ty_flight.
DATA: lt_flight TYPE TABLE OF ty_flight,
lo_salv TYPE REF TO cl_salv_table.
" --- Selection Screen ---
SELECT-OPTIONS: so_carrid FOR lt_flight-carrid.
" --- Start of Selection ---
START-OF-SELECTION.
SELECT carrid connid fldate price currency
FROM sflight
INTO TABLE lt_flight
WHERE carrid IN so_carrid.
IF lt_flight IS INITIAL.
MESSAGE 'No data found' TYPE 'I'.
RETURN.
ENDIF.
PERFORM display_alv.
" --- ALV Display Form ---
FORM display_alv.
DATA: lo_columns TYPE REF TO cl_salv_columns_table,
lo_column TYPE REF TO cl_salv_column_table,
lo_display TYPE REF TO cl_salv_display_settings,
lo_funcs TYPE REF TO cl_salv_functions_list.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_salv
CHANGING t_table = lt_flight ).
" Enable standard toolbar functions
lo_funcs = lo_salv->get_functions( ).
lo_funcs->set_all( abap_true ).
" Optimize columns
lo_columns = lo_salv->get_columns( ).
lo_columns->set_optimize( abap_true ).
" Set column texts
lo_column ?= lo_columns->get_column( 'CARRID' ).
lo_column->set_long_text( 'Carrier' ).
lo_column ?= lo_columns->get_column( 'FLDATE' ).
lo_column->set_long_text( 'Flight Date' ).
lo_column ?= lo_columns->get_column( 'PRICE' ).
lo_column->set_long_text( 'Ticket Price' ).
" Display settings
lo_display = lo_salv->get_display_settings( ).
lo_display->set_striped_pattern( cl_salv_display_settings=>true ).
lo_display->set_list_header( 'Flight Schedule Report' ).
" Display ALV
lo_salv->display( ).
CATCH cx_salv_msg INTO DATA(lx_msg).
MESSAGE lx_msg->get_text( ) TYPE 'E'.
ENDTRY.
ENDFORM.
This ALV report sample within SAP ABAP shows a ready-to-use, clean implementation that you can utilize as a model in your projects.
Conclusion
ALV reports that are part of SAP ABAP can be an essential element in SAP development. If you're building a grid-based display that is simple or an interactive ALV report within SAP ABAP or a hierarchy-based ALV report or a fluid ALV solution, the ALV framework provides the user a solid base to build from.
Here's a quick overview of the topics we discussed:
- ALV full form in SAP ABAP — The ABAP List Viewer
- ALV grid display — Most common display method using REUSE_ALV_GRID_DISPLAY or CL_SALV_TABLE
- ALV report events — USER_COMMAND, TOP_OF_PAGE, etc. allow interactivity
- Interactive ALV — Drill-down from summary to detail by using event handling
- OOPs ALV — Modern, clean approach using CL_SALV_TABLE
- Hierarchical ALV — Parent-child data display with REUSE_ALV_HIERSEQ_LIST_DISPLAY
- Dynamic ALV — Field catalog built at runtime utilizing RTTI
- Adding buttons — Modification of PF-Status with the CALLER_EXIT event
- Refreshing ALV — Using refresh_table_display( ) or lo_salv->refresh( )
Professionals who want to master SAP ABAP development, spending the time to study ALV is among the most high-ROI skills you could develop. Begin with the basic grid display, move on to OOPs ALV, and move on to interactive and the hierarchical report as your proficiency increases.
Related SAP Training Courses
Tags
Share this article
Help others discover this valuable SAP content


