Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Program Flow →  Obsolete Control Structures 

ON CHANGE OF

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

ON CHANGE OF dobj [OR dobj1 [OR dobj2] ... ].
  statement_block1
[ELSE.
  statement_block2]
ENDON.

Effect

The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain two statement blocks: statement_block1 and statement_block2. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added, linked by OR.

The first time a statement ON CHANGE OF is executed, the first statement block 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 statement 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 statement_block2 after ELSE is executed if the first statement block is not executed.

For each time the statement ON CHANGE OF is executed, the content of all the specified data objects is saved as an auxiliary variable internally in the global system. The auxiliary variable is linked to this statement and cannot be accessed in the program. The auxiliary variables and their contents are retained longer than the lifetime of procedures. An auxiliary variable of this type can only be initialized if its statement ON CHANGE OF is executed while the associated data object is initial.


Note

This control structure is particularly prone to errors and should be replaced by branches with explicitly declared auxiliary variables.


Example

In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed.

DATA spfli_wa TYPE spfli. 

SELECT * 
       FROM spfli 
       INTO spfli_wa 
       ORDER BY carrid. 

  ... 

  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 auxiliary variable carrid_buffer.

DATA: spfli_wa TYPE spfli, 
      carrid_buffer TYPE spfli-carrid. 

CLEAR carrid_buffer. 

SELECT * 
       FROM spfli 
       INTO spfli_wa 
       ORDER BY carrid. 

  ... 

  IF spfli_wa-carrid <> carrid_buffer. 
    carrid_buffer = spfli_wa-carrid. 
    ... 
  ENDIF. 

  ... 

ENDSELECT.

Continue

ENDON