Try OpenEdge Now
skip to main content
ABL Essentials
Running ABL Procedures : Using external and internal procedures : RETURN statement and RETURN-VALUE
 

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:
RETURN [return-value].
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:
RUN subproc (INPUT cParam).
IF RETURN-VALUE = ... THEN
  ...
If the called procedure doesn't 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's 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.