Below is the list of events from the Classical and Interactive reports in SAP.
INITIALIZATION
Trigger Point – This event occurs before the standard selection screen is displayed.
Purpose– To initialize the input fields of the standard selection screen
Code Example – In the example below, we are initializing the Input Parameter ‘p_mtart’ with the value ‘FERT’. So when the Selection screen appears, the Parameter ‘p_mtart’ will have an initial value of ‘FERT’. If the user wants, they can modify that value as well on the Selection screen.
" INITIALIZATION event
INITIALIZATION.
p_mtart = 'FERT'. " Default value
WRITE: / 'INITIALIZATION: Default material type is set to FERT'.
AT SELECTION-SCREEN OUTPUT
Trigger Point– This event is triggered before the selection screen is displayed.
Purpose– It allows to modify the elements of screen dynamically. We can change the attributes of each field like visibility , Input Enable/Disabled e.t.c
Code Example– We check screen-name is ‘p_matnr’, if yes we make it Input disabled.
" AT SELECTION-SCREEN OUTPUT event
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_MTART'.
screen-input = '0'. " Make it no editable
MODIFY SCREEN.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON
Trigger Point– This event triggers before leaving the selection screen. Once the ABAP runtime environment has passed all the input data from the selection screen to the ABAP programme.
Purpose– To validate the input provided through the selection screen on a particular field. If an error message occurs in the processing block, only that single field will be ready for input after the message is displayed.
Code Example– If ‘p_matnr’ is initial, only the input field ‘p_matnr’, will be input ready once the error message is displayed.
" AT SELECTION-SCREEN ON event
AT SELECTION-SCREEN on p_matnr.
IF p_matnr is INITIAL.
MESSAGE 'Please pass the value of material' TYPE 'E'.
ENDIF.
AT SELECTION-SCREEN
Trigger Point– This event triggers before leaving the selection screen. Once the ABAP runtime environment has passed all the input data from the selection screen to the ABAP programme.
Purpose– To validate the input provided through the selection screen. If an error message occurs in the processing block, the selection screen is redisplayed with all of its fields ready for input.
Code Example– If ‘p_ernam’ is initial, all the remaining input fields ‘p_matnr’, ‘p_ernam’, and ‘p_mtart’ will be input ready, once the error message is displayed.
PARAMETERS: p_matnr TYPE mara-matnr,
P_ernam TYPE mara-ERNAM,
p_mtart TYPE mara-mtart.
**AT SELECTION-SCREEN event
AT SELECTION-SCREEN.
IF P_ernam is INITIAL.
MESSAGE 'Please pass the value of material' TYPE 'E'.
ENDIF.
START-OF-SELECTION
Trigger Point– This event triggers after the selection screen is processed and before data is read using the logical database.
Purpose– ‘REPORT’ statement always executes the ‘START-OF-SELECTION’ event implicitly. Non-declarative statement that occurs between REPORT and the first processing block, also processed in the START-OF-SELECTION block.
Code Example–
" START-OF-SELECTION event
START-OF-SELECTION.
WRITE: / 'START-OF-SELECTION: Fetching data from MARA'.
SELECT * FROM mara
INTO TABLE it_mara
WHERE matnr = p_matnr OR mtart = p_mtart.
TOP-OF-PAGE
Trigger Point– This is an ALV list processing event that triggers before the fist data is written on a new page.
Purpose– It helps us to write the HEADER of a page.
Code Example–
" TOP-OF-PAGE event
TOP-OF-PAGE.
WRITE: / 'TOP-OF-PAGE: Material Report from MARA Table'.
ULINE.
END-OF-PAGE
Trigger Point– This event triggers at the end of the page.
Purpose– To print the same footer details for all the pages
Code Example–
" END-OF-PAGE event
END-OF-PAGE.
WRITE: / 'END-OF-PAGE: Page Footer - Confidential Data'.
END-OF-SELECTION
Trigger Point– This is the last of the events called by the ABAP runtime environment. It is triggered after all the data has been read from the logical database and before the list processor is started.
Purpose– Used to print the final output. Used to print the total when working with a logical database.
Code Example–
" END-OF-SELECTION event
END-OF-SELECTION.
IF it_mara IS INITIAL.
WRITE: / 'No data found for the given criteria.'.
ELSE.
LOOP AT it_mara INTO wa_mara.
WRITE: / wa_mara-matnr, wa_mara-mtart, wa_mara-mbrsh, wa_mara- matkl.
ENDLOOP.
ENDIF.
AT LINE-SELECTION
Trigger Point– Trigger for line selected from output list
Purpose– Used to print the secondary list based on the selected line content.
Code Example–
AT USER-COMMAND
Trigger Point– Triggers for the User Interaction through function keys.
Purpose– To validate User Command and Display the secondary List.
Code Example–
TOP-OF-PAGE DURING LINE SELECTION
Trigger Point– Triggers on top of each secondary list.
Purpose– To print the header on the Secondary list.
Code Example–
COMPLETE PROGRAMME
*&---------------------------------------------------------------------*
*& Report ZALV_4
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZALV_4.
TABLES: mara.
" Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_matnr TYPE mara-matnr,
P_ernam TYPE mara-ERNAM,
p_mtart TYPE mara-mtart.
SELECTION-SCREEN END OF BLOCK b1.
" Internal Table and Work Area
DATA: it_mara TYPE TABLE OF mara,
wa_mara TYPE mara.
" Text symbols
*TEXT-001 = 'Material Selection'.
" INITIALIZATION event
INITIALIZATION.
p_mtart = 'FERT'. " Default value
WRITE: / 'INITIALIZATION: Default material type is set to FERT'.
" AT SELECTION-SCREEN OUTPUT event
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_MTART'.
screen-input = '1'. " Make it editable
MODIFY SCREEN.
ENDIF.
ENDLOOP.
**AT SELECTION-SCREEN. event
AT SELECTION-SCREEN.
IF P_ernam is INITIAL.
MESSAGE 'Please pass the value of material' TYPE 'E'.
ENDIF.
" AT SELECTION-SCREEN ON event
AT SELECTION-SCREEN on p_matnr.
IF p_matnr is INITIAL.
MESSAGE 'Please pass the value of material' TYPE 'E'.
ENDIF.
" START-OF-SELECTION event
START-OF-SELECTION.
WRITE: / 'START-OF-SELECTION: Fetching data from MARA'.
SELECT * FROM mara
INTO TABLE it_mara
WHERE matnr = p_matnr OR mtart = p_mtart.
* TOP-OF-PAGE event
TOP-OF-PAGE.
WRITE: / 'TOP-OF-PAGE: Material Report from MARA Table'.
ULINE.
" END-OF-SELECTION event
END-OF-SELECTION.
IF it_mara IS INITIAL.
WRITE: / 'No data found for the given criteria.'.
ELSE.
LOOP AT it_mara INTO wa_mara.
WRITE: / wa_mara-matnr, wa_mara-mtart, wa_mara-mbrsh, wa_mara-matkl.
ENDLOOP.
ENDIF.
" END-OF-PAGE event
END-OF-PAGE.
WRITE: / 'END-OF-PAGE: Page Footer - Confidential Data'.
What is the sequence of ALV Events in the Classical Report?
List of standard classical report events in the order they are triggered:
LOAD-OF-PROGRAM
Triggered once when the program is loaded into memory (rarely used).
INITIALIZATION
Used to initialize variables and default selection screen values.
AT SELECTION-SCREEN ON <field>
Field-level validation.
AT SELECTION-SCREEN
Validates selection screen entries (called after user input).
START-OF-SELECTION
Used in logical database reports.
END-OF-SELECTION
Called after START-OF-SELECTION
— typically used to display the output (e.g., call ALV here).
TOP-OF-PAGE
Writes the page header in classical list reports. (ALV FM uses this via callback.)
END-OF-PAGE
Writes the page footer.