Event blocks 

Event blocks are introduced by an event keyword. They end when the next processing block begins. The following processing block may be another event block, introduced by a different event keyword, or another processing block that is valid in the context, such as a subroutine or dialog module. Event keywords have the same name as the events to which they react.

Example for the structure of an executable program:

REPORT...

NODES: SPFLI, SFLIGHT.

DATA:...

INITIALIZATION.
...

AT SELECTION-SCREEN.
...

START-OF-SELECTION.
...

GET SPFLI...
..

GET SFLIGHT...
...

GET SPFLI LATE.
...

END-OF-SELECTION.
...

FORM...
...
ENDFORM.

The sequence in which the processing blocks occur in the program is irrelevant. The actual processing sequence is determined by the external events. However, to make your programs easier to understand, you should include the event blocks in your program in approximately the same order in which they will be called by the system. Subroutines should be placed at the end of the program.

With only two exceptions (AT SELECTION-SCREEN and GET), event blocks have no local data area. All declarative statements in event blocks are handled with the global data declarations in the program. You should therefore include all of your declarations at the start of the program (see also Structure of ABAP Programs).

Statements that are not assigned to a processing block are never executed. An exception to this are any non-declarative statements between the REPORT or PROGRAM statement and the first processing block, which are assigned to the default event
START-OF-SELECTION if a program does not contain an explicit START-OF-SELECTION block, these statements form the entire START-OF-SELECTION block. If a START-OF-SELECTION keyword is already included in your program, these statements are inserted at the beginning of this block. If the program does not contain any explicit event blocks, all non-declarative statements are assigned to the default processing block START-OF-SELECTION.

REPORT EVENT_TEST.

WRITE / 'Statement 1'.

FORM ROUTINE.
  WRITE / 'Subroutine'.
ENDFORM.

WRITE / 'Statement 2'.
PERFORM ROUTINE.
WRITE / 'Statement 3'.

This produces the following output:

Statement 1

Only the event block START-OF-SELECTION is started in this program. This block consists of the first WRITE statement.

Now we insert a START-OF-SELECTION statement in the program:

REPORT EVENT_TEST.

WRITE / 'Statement 1'.

FORM ROUTINE.
  WRITE / 'Subroutine'.
ENDFORM.

START-OF-SELECTION.
  WRITE / 'Statement 2'.
  PERFORM ROUTINE.
  WRITE / 'Statement 3'.

The output is now as follows:

Statement 1

Statement 2

Subroutine

Statement 3

In this program, the START-OF-SELECTION processing block consists of all statements except the FORM-ENDFORM block. A more readable form of the same program would look like this:

REPORT SAPMZTST.

START-OF-SELECTION.
  WRITE / 'Statement 1'.
  WRITE / 'Statement 2'.
  PERFORM ROUTINE.
  WRITE / 'Statement 3'.

FORM ROUTINE.
  WRITE / 'Subroutine'.
ENDFORM.

In this case, you could also omit the event keyword START-OF-SELECTION.