You can add ABAP Code in SAP Query report to enhance your report, Open your infoset via tcode SQ02 and click Extras button toolbar.

add-abap-code-sapquery

You can choose any event depend on your requirement to add your ABAP Code.

add-abap-code-sapquery-saptutorial

These are the explanation for Event in listbox Code Section :

  • DATA Section :

       Global Data Declaration will go under this Event.

  • INITIALIZATION Section :

As the name suggests it is used to initialize the variable with initial values.

  • AT SELECTION-SCREEN OUTPUT :

This event is triggered before the display of selection screen.

  • START-OF-SELECTION :

This event is triggered before starting any database accesses. Usually Data fetching logic goes under it.

  • RECORD Processing :

Corresponds to the GET coding with Info-sets without a logical database. As there is no hierarchical view of the data, all the join tables are addressed.

  • END-OF-SELECTION :

The END-OF-SELECTION code consists of two parts (Before list output and After list output). The first part is processed before the list is output and the  second  part afterwards. 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.

For Example Case :

Add Variable Declaration in DATA code section event.

<GI00> is the Internal table which contain result data that to be displayed on report. you can modify this internal table.

END-OF-SELECTION ( After List )