Expand and collapse in ALV
Today one of the member of our telegram group asked how to add a button into the cells of a column to expand and collapse more rows with details.
Question and decision how to solve the task
- Is the function already implemented in SAP demo reports or productive reports?
- Yes, you can find the function in transaction ME2ON
- Is it easy to replicate the function from the report of SAP into own development?
- No, because the new MM-Developments are very complex developed. The function is handled not directly by the ALV, instead it is handled by leaving and returning to the screen.
Solution
I have added a button with hotspot in the cells of one column for the function.
There are two additional button in the toolbar of the ALV to expand or collapse details of all rows. If the button expand all detail is triggered, then all details for the rows which contain expand button are added right below the rows and the ALV will be refreshed.
Get the source code from GitHub
Download
You can download the soure code from GitHub. Available Versions are:
Usage of cl_salv_table
Usage of cl_gui_alv_grid
Import using abapGit
Or you can import the source code directly into your system by using abapGit. You can find more information about how to import repo from GitHub here.
Copy the repo links https://github.com/stekoester/exp_col_in_salv
or https://github.com/stekoester/exp_col_in_alv