Show TOC

Event BlocksLocate this document in the navigation structure

Event blocks are introduced by an event keyword. They end when the next processing block begins. The following processing block can either be an event block or another processing block allowed in this context - for example, a subroutine or a dialog module. Event keywords have the same name as the events to which they react.

Tip

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. In executable programs, all non-declarative statements between the REPORT or PROGRAM statement and the first processing block are assigned to the default event START-OF-SELECTION. if a program does not contain an explicit START-OF-SELECTION event block, these statements form the entire START-OF-SELECTION block. If a program contains an explicitly defined START-OF-SELECTION event block, these statements are inserted at the beginning of this event block. If a program does not contain any explicit event blocks, all non-declarative statements form the processing block START-OF-SELECTION.

Tip

REPORT demo_abap_events_1.

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 demo_abap_events_2.

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 demo_abap_events_3.

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.