ON CHANGE OF
ON CHANGE OF dobj [OR dobj1 [OR dobj2] ...].
ON CHANGE OF and
ENDON, which are forbidden in classes, define a
that can contain two statement blocks:
ON CHANGE OF, any number of data objects
dobj2... of any data type can be added, linked by
The first time a statement
ON CHANGE OF is executed, the first statement
statement_block1 is executed if at least one of the specified data
objects is not initial. The first statement block is executed for each additional execution of the same
ON CHANGE OF, if the content of one of the specified data objects
has been changed since the last time the statement
ON CHANGE OF was executed.
The optional second statement block
ELSE is executed if the first statement block is not executed.
Each time the statement
ON CHANGE OF is executed, the content of all the
specified data objects is saved as a helper variable internally in the global system. The auxiliary
variable is linked to this statement and cannot be accessed in the program. The helper variables and their content are preserved longer than the lifetime of
procedures. A helper variable
of this type can only be initialized if its statement
ON CHANGE OF is executed while the associated data object is initial.
This control structure is particularly prone to errors and should be replaced by branches with explicitly declared helper variables.
SELECT loop, a statement block should only be executed if the content of column CARRID has changed.
DATA spfli_wa TYPE spfli. SELECT * FROM spfli ORDER BY carrid INTO @spfli_wa. ... ON CHANGE OF spfli_wa-carrid. ... ENDON. ... ENDSELECT.
The following section of a program shows how the
ON control structure can
be replaced by an
IF control structure with an explicit helper variable
DATA: spfli_wa TYPE spfli, carrid_buffer TYPE spfli-carrid. CLEAR carrid_buffer. SELECT * FROM spfli ORDER BY carrid INTO @spfli_wa. ... IF spfli_wa-carrid <> carrid_buffer. carrid_buffer = spfli_wa-carrid. ... ENDIF. ... ENDSELECT.