RETURN statement and RETURN-VALUE
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
RETURN statement and RETURN-VALUE
Whenever a procedure, whether internal or external,
terminates and returns control to its caller, it returns a value
to the caller. You can place a RETURN statement
at the end of your procedure to make this explicit, and to specify
the value to return to the caller:
|
The return-value must be a character value,
either a literal or an expression. The caller (calling procedure)
can access this return-value using the built-in RETURN-VALUE function,
such as in this example:
|
If the called procedure does not return a value, then the value returned is
either the empty string ("") or, if an earlier procedure RUN statement in the same call stack returned a value, then that
value is returned.
The RETURN statement is optional in
procedures. Because an earlier RETURN-VALUE is passed back up
through the call stack if there is no explicit RETURN
statement to erase it, it is good practice to have the statement RETURN "" at the end of every procedure to clear any old value, unless your
application needs to pass a RETURN-VALUE back through
multiple levels of a procedure call.
In addition, you can return to the calling procedure from multiple
places in the called procedure by using multiple RETURN statements in
different places. You could use this technique, for example, to
return one return-value representing success
(possibly the empty string) and other return-values
from different places in the procedure code to indicate an error
of some kind.