ALV

Expand and Collapse Detail Lines in SAP ALV via ABAP

This article demonstrates how to dynamically expand and collapse additional detail information within the SAP ALV. The solution focuses on a practical ABAP implementation featuring intuitive user guidance and manageable grid interactions.

Initial Question and Solution Strategy

  1. Are there already standard demo or production programs within SAP that utilize this feature?
    • Yes, you can find this functionality active inside transaction ME2ON.
  2. Can the functionality be directly copied and reused from these standard SAP programs?
    • No, because the modern MM transactions leverage a complex program workflow. The feature is not executed natively by the ALV grid component itself, but rather by leaving and re-calling the underlying dynpro screen.

How the Solution Operates within the ALV Grid

To support this interaction, I integrated a button component combined with a hotspot configuration into a dedicated column.

Once the button is triggered by the user, the corresponding event handler inserts additional details directly beneath the line and refreshes the ALV layout.
By appending details to the row, the expand icon is dynamically swapped with the collapse symbol. Retriggering the button removes the details from the view and triggers an ALV layout refresh.

The ALV application toolbar also features two distinct buttons to either expand or collapse all details with a single interaction. When the expand command is triggered, the detailed datasets for all rows configured with an expand button are inserted directly beneath each respective line, followed by an immediate ALV grid refresh.

Triggering the collapse all command removes all open detail sub-rows from the grid and updates the view rendering.

Download Source Code on GitHub

Select the appropriate variant matching your SAP release version.

Technology Minimum Release GitHub
cl_salv_table SAP_BASIS 702 Open Repository
cl_salv_table SAP_BASIS 740SP02 Open Repository
cl_salv_table SAP_BASIS 740SP08 Open Repository
cl_gui_alv_grid SAP_BASIS 702 Open Repository
cl_gui_alv_grid SAP_BASIS 740SP02 Open Repository
cl_gui_alv_grid SAP_BASIS 740SP08 Open Repository

Import GitHub Repo via abapGit

You can also import the source code directly into your system using abapGit. You can find a step-by-step guide for importing from a GitHub repository in the linked blog post.

Open instructions for importing with abapGit

Repository URLs zum Kopieren

https://github.com/stekoester/exp_col_in_salv
https://github.com/stekoester/exp_col_in_alv

Back to Blog Overview