SAP ON ABAP Statements

Warning: Undefined variable $saptab in /customers/b/9/9/trailsap.com/httpd.www/abap-statements/index.php on line 46

Get Example source ABAP code based on a different SAP table
  

Warning: Undefined variable $prev in /customers/b/9/9/trailsap.com/httpd.www/abap-statements/index.php on line 62
Standard SAP Help for ON

ON CHANGE OF

Short Reference
• ON CHANGE OF ABAP Statement
• OR ON CHANGE OF (obsolete)
• ELSE ON CHANGE OF (obsolete)

ABAP Syntax(Obsolete)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 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.
INTHINT Horribile dictu - an ELSEIF is also possible.



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



Example ABAP Coding
: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.

Return to menu