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.
I have added a button with hotspot in the cells of one column for the function. If the button is triggered by the user, then the event handler adds more details right below the row and refreshes the ALV. Due to adding the details for the row the expand icon is replaced by the collapse icon. If this button is triggered then, then the details will be removed from the ALV and the ALV will be refreshed.
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. If the button collapse all detail is triggered, then all details for the rows which contain collapse button are removed from the rows and the ALV will be refreshed.
Get the source code from GitHub
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