Let's have a look at a general structure of the program events to understand where it is necessary to place the custom code.
There are a number of events in the lifecycle, which can be introduced in the program through the following keywords in order to place the custom code inside them. Note that event block are internal to the program, they are triggered by the runtime environment at the defined points of execution and cannot be called programmatically.
Program constructor events
LOAD-OF-PROGRAM
Servers as a program constructor. Called by environment when the program is loaded into internal session memory, triggered only once per program execution. Used to initialize the global data.
Reporting events
INITIALIZATION
The first event triggered when the program is executed, executed immediately after the LOAD-OF-PROGRAM
. If the program has a selection screen defined, INITIALIZATION
event is called after the selection screen code has been processed first time by runtine environment but before the selection screen is dispayed to the user. Can be used to initialize input fields, change the default values of them or initialize all of the values in the program. The event is triggered only once per program execution, any subsequent call to the selection screen would not trigger this even again. For initializing or modifying the selection screen fields often the selection sreen events are preferred.
Note: Selection screen events (see below) are executed between INITIALIZATION
and START-OF-SELECTION
START-OF-SELECTION
Called after the INITIALIZATION
event. If the program has a selection screen defined, this is the first event triggered after all selection screen events. It is a standard event: if no other events are declared, there is no need to code this event manually, all processing statements are automatically assigned to an implicit START-OF-SELECTION
block. Any statements between the global declaration area and the first processing block of the program are automatically inserted at the beginning of the event. All the program logic goes into this event block.
Selection screen events
they are called when a selection screen is processed
AT SELECTION-SCREEN OUTPUT
is a PBO - process before output - event, triggered before the screen is displayed to the user
can use this event block in the program to react to the event and execute code to dynamically change field properties (i.e. enable / disable fields) or to assign default values
AT SELECTION-SCREEN
is a PAI - process after input - event, triggered after user takes some action on the displayed screen (i.e. clicking a button)
this is a default PAI event triggered after all the selection screen events
are executed, can be used to validate user inputs
there are several other specific PAI events available, which allow more fine-grained control: AT SELECTION-SCREEN
ON <field>
| END OF <sel>
| BLOCK
| RADIO BUTTON GROUP
Having this overview it should be clear, that conditions, looping at and modifying the screen should go inside the AT SELECTION-SCREEN OUTPUT
event - process before output, modification of the selection screen should be done before it will be displayed to a user.
In case as you wrote it (used AT SELECTION-SCREEN OUTPUT
inside the condition) places this whole part of code to the default START-OF-SELECTION
event block and does not lead to the desired result.