SAP ON ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID ON
• ON CHANGE OF ABAP Statement
• OR ON CHANGE OF (obsolete)
• ELSE ON CHANGE OF (obsolete)

ON CHANGE OF
Short Reference

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

What does it do?
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 linked by OR can be specified.
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 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.
Each time the statement ON CHANGE OF is executed, the content of all the specified data objects is stored in an internal helper variable that is global to the program. This helper 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.
BEGIN_SECTION SAP_INTERNAL_HINT
<(>Horribile dictu<)> - an ELSEIF is also possible.
END_SECTION SAP_INTERNAL_HINT



Latest notes:

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



Example ABAP Coding

In a SELECT loop, a statement block should only be executed if the content of column CARRID has changed.
ABEXA 00454
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 carrid_buffer.
ABEXA 00455
ABAP_EXAMPLE_END

Return to menu