You can exit procedures in the usual way using the
END... statement or by using one of the following statements:
These statements end a procedure properly, that is, the system passes output parameters for which passing by value is specified and returns values to the assigned actual parameters. In addition, you can terminate the processing of a procedure as follows, whereby the actual parameters are not supplied with values:
- Calling another unit (program, dynpro) without returning to the procedure
- Triggering an exception or sending a dialog message if an error occurs
Only use RETURN to exit procedures
RETURN statement to properly exit a procedure (method, see rule
no implementations in function modules and subroutines) early.
RETURN statement serves to exit procedures and always has this result.
The behavior of the
(conditional exit), in contrast, is context- dependent: Within a loop, only the loop is exited; outside
a loop, the surrounding procedure is exited. This ambiguity limits the legibility of source code. Therefore,
CHECK should only be used to exit loops,
RETURN only to exit procedures. Only
RETURN enables you to exit a procedure in a loop context.
As well as the statements
CHECK listed here, the statements
STOP can be used to exit special
event blocks. Conversely,
can also exit processing blocks other than procedures. In both cases, you must consider the particular
behavior of the ABAP runtime environment regarding the exited processing block. Because other processing blocks are only supposed to contain one method call according to the rules
use ABAP Objects and
no implementations in dialog modules and event blocks, these cases should no longer occur in new programs.
An exception to the rule to only use
RETURN to exit procedures are
CHECK statements that are located at the beginning of a procedure and that check the prerequisites
for the execution of the procedure there. Using the
CHECK statement in such
a way does not impair the legibility and is thus allowed. However, this exception does not apply to other positions within a procedure and outside loops.
The following source code shows how a method is left early with a
whose meaning cannot be identified by simply looking at it. You have to know that
exits the procedure if the following logical expression is wrong, which is why a double negation is necessary here.
CHECK is_finished = abap_false.
The following source code corrects and simplifies the above example by implementing a conditional exit with an
IF control structure that is easy to read.
IF is_finished = abap_true.