Sequence of Events in ABAP Program

 Sequence of Events in ABAP Program

This article explains the usage of events in ABAP program.

In a classical ABAP report, the following events are used.
  1. Load of program
  2. Initialization
  3. At selection screen output
  4. At selection screen on field
  5. At selection screen on value request
  6. At selection screen on help request
  7. At selection screen
  8. Start-of-selection
  9. End of selection
  10. Top of page
  11. End of page
Here is a simple ABAP program that explains the sequence of the above events mentioned:
REPORT ZEVENTS.

DATA: gv_field TYPE string.

PARAMETERS: p_field TYPE string.

INITIALIZATION.
  " Event 1: Load of Program
  " This event is triggered when the program is loaded into the internal session.
  WRITE: / 'Event 1: Load of Program'.

AT SELECTION-SCREEN OUTPUT.
  " Event 3: At Selection Screen Output
  " This event is triggered before the selection screen is displayed.
  WRITE: / 'Event 3: At Selection Screen Output'.

AT SELECTION-SCREEN ON p_field.
  " Event 4: At Selection Screen on Field
  " This event is triggered after the user enters a value in the field on the selection screen.
  WRITE: / 'Event 4: At Selection Screen on Field'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field.
  " Event 5: At Selection Screen on Value Request
  " This event is triggered when the user requests possible entries for a field.
  WRITE: / 'Event 5: At Selection Screen on Value Request'.

AT SELECTION-SCREEN ON HELP-REQUEST FOR p_field.
  " Event 6: At Selection Screen on Help Request
  " This event is triggered when the user requests help for a field.
  WRITE: / 'Event 6: At Selection Screen on Help Request'.

AT SELECTION-SCREEN.
  " Event 7: At Selection Screen
  " This event is triggered after the user makes a selection and before the selection screen is processed.
  WRITE: / 'Event 7: At Selection Screen'.

START-OF-SELECTION.
  " Event 8: Start of Selection
  " This event is triggered after the selection screen is processed.
  WRITE: / 'Event 8: Start of Selection'.

  " Event 10: Top of Page
  " This event is triggered when a new page is started in the list.
  WRITE: / 'Event 10: Top of Page'.

  " Event 9: End of Selection
  " This event is triggered at the end of the event block START-OF-SELECTION.
  WRITE: / 'Event 9: End of Selection'.

END-OF-SELECTION.
  " Event 11: End of Page
  " This event is triggered at the end of a page in the list.
  WRITE: / 'Event 11: End of Page'.

The events Load of Program and Initialization are not explicitly shown in the code as they are implicit events that occur when the program is loaded and initialized respectively.

Field validations in ABAP programs are typically handled in the AT SELECTION-SCREEN event. This event is triggered after the user enters values on the selection screen and hits the execute button, but before the actual processing of the selection screen takes place.

Here’s an example of how you might use this event to validate a field:
AT SELECTION-SCREEN.
  IF p_field IS INITIAL.
    MESSAGE 'Field cannot be empty' TYPE 'E'.
  ENDIF.
Please note that sometimes the sequence of events may vary based on the user interactions and the logic in your program.

Post a Comment

Previous Post Next Post