Sap List Viewer queries using code in the END-OF-SELECTION section
Reports and Queries using the “Sap List Viewer” format are a huge improvement from the old “ABAP List” format. Columns can be moved by drag and drop, export options are better, looks are nicer and it has many other advantages.
The END-OF-SELECTION section is very handy. It runs after the records have been processed by the query but before the report is displayed. It is the right section to do aggregated calculations and actions that can only be done when data from all the selected records has been extracted.
However, there is a problem when queries use code in the END-OF-SELECTION section in combination with the Sap List Viewer format. In short, the code is never reached.
Here is a trick to make the combination work.
When defining the query change the output format option to ABAP List. This will trigger the old source code generation that includes the code in the END-OF-SELECTION section.
Run the query and in the selection screen change the option to SAP List Viewer.
Save a default variant
Include any other default values that you may need for the selection fields in the query.
Change the query and add the default variant as the standard variant of the query.
In this way, the query is generated internally for an “ABAP List” report and it will include the END-OF-SELECTION code. When the query is executed, the default variant will change the option and the query will display with a flexible “SAP List Viewer” format.