RETURN statement
Leaves the local or remote procedure or user-defined function block, trigger block, database trigger block, the method block of a class, the class constructor block, or the property accessor block, and returns to the calling procedure, user-defined function, method, constructor, or property accessor. If there is no caller, RETURN returns to the Procedure Editor or other ADE or OpenEdge Architect tool that invoked the procedure, user-defined function, trigger block, database trigger, class-based method, constructor, or property accessor.
For more information on remote procedures, see OpenEdge Application Server: Developing AppServer Applications.
Syntax
return-value
The value that RETURN returns to the caller, with or without the ERROR condition:
- Without the ERROR condition — In a procedure or trigger block, the optional
return-value
must be a CHARACTER expression. If you do not specifyreturn-value
in a procedure or trigger block,return-value
is returned as the empty string (""). In a VOID method, you cannot set areturn-value
. In a user-defined function or in a method of a class that returns a value (non-VOID),return-value
must be specified and must be an expression whose data type matches the return type of the function or method; data type matching between the expression and return type follows the data type widening rules for an expression passed to an OUTPUT parameter (see the Parameter passing syntax reference entry for more information).- With the ERROR condition — In a method of a class (VOID or non-VOID), a constructor, a property accessor, a user-defined function, a procedure, or a database trigger block, the optional
return-value
must be a CHARACTER expression. If you do not specify eitherreturn-value
orerror-object-expression
(see the ERROR option),return-value
is returned as the empty string ("").For more information on how the caller can accessreturn-value
in each case, see the ERROR option.ERROR
Causes an ERROR condition in the calling block. This can cause the ERROR condition to be raised for the following statements in the caller:
- The RUN statement for a procedure
- Any statement that invokes a user-defined function
- Any statement that invokes a method of a class
- Any statement that invokes the NEW function (classes) to instantiate a class (invoking the specified constructor and all other constructors for the class hierarchy)
- Any statement that accesses a property defined with a property accessor
You can use the ERROR option in a procedure, database trigger block, class-based method, constructor, property accessor method, or user-defined function. However, you cannot use the ERROR option in a user-interface trigger block to raise ERROR outside of the trigger block. Any values that are set for OUTPUT or INPUT-OUTPUT parameters before the RETURN ERROR executes are not returned to the caller.Ifreturn-value
is specified, the ABL Virtual Machine (AVM) automatically generates aProgress.Lang.AppError
that the caller can obtain using a CATCH statement and obtainreturn-value
from theReturnValue
property of the AppError. If noreturn-value
orerror-object-expression
is specified, the AVM also generates anAppError
with itsReturnValue
property set to the empty string (""). The following table shows how to accessreturn-value
in the caller in various cases:
In this case . . .
How to retrieve the return value
in the caller . . . Thereturn-value
is specified without the ERROR option in a procedure or trigger block. Access the RETURN-VALUE function. Thereturn-value
is specified for a non-VOID method or user-defined function without the ERROR option. In this case, the caller accesses the method or function return value by referencing the function or method call in an expression, similar to referencing a variable. Thereturn-value
is specified with the ERROR option. Access the RETURN-VALUE function, or CATCH theProgress.Lang.AppError
object automatically created by the AVM and check theReturnValue
property of theAppError
object.Note: User-defined functions have different behavior since they must return the data type specified in the definition. See the "FUNCTION statement" section for more information. Theerror-object-expression
is specified Iferror-object-expression
is aProgress.Lang.AppError
, CATCH the specified error object and access itsReturnValue
property, or access the RETURN-VALUE function.error-object-expression
An expression that resolves to a specific error object. It must be an object derived fromProgress.Lang.ProError
(you can only THROW error objects) or an object of a class that implementsProgress.Lang.Error
. It is a compile-time error to THROW an object that is not derived fromProgress.Lang.ProError
orProgress.Lang.Error
. Note that the only error object that you can instantiate directly is aProgress.Lang.AppError
object or a subclass.Note: RETURN ERRORerror-object-expression
immediately returns to the caller before throwing the error object. Unlike a direct THROW, it ignores any CATCH blocks or ON ERROR directives in effect at the time of the RETURN.NO-APPLY
Suppresses the default behavior for the current user-interface event. You thus can use the NO-APPLY option in a user-interface trigger block to suppress that behavior. For example, the default behavior for a character code key press in a fill-in field is to echo the character in the field. If you execute RETURN NO-APPLY in a trigger, this behavior is not performed. Also, NO-APPLY returns without setting areturn-value
or error object.If you do not specify any options for the RETURN statement in a procedure or trigger block,
return-value
is returned as the empty string (""). In a VOID method, you cannot specify any options except for the ERROR options, and RETURN without ERROR options returns without setting areturn-value
or error object.ExamplesThe
r-fact.p
procedure is called recursively because (n
factorial) isn
* ((n
- 1) factorial). Ther-fact.p
procedure first checks that the input value is valid. If the value is invalid, it returns a message to the caller. Note thatr-return.p
checks the ReturnValue property immediately after runningr-fact.p
. If a message is returned,r-return.p
displays that message.The procedure
r-return.p
accepts an integer as input and then runsr-fact.p
to calculate the factorial of that integer. The factorial of a number is the result of multiplying together all of the integers less than or equal to that number (for example: 3 factorial is 3 * 2 * 1 = 6). Ther-fact.p
procedure is called recursively becausen
factorial isn
* (n
-1) factorial.
Note that this is not the most efficient way to calculate factorials, but in other applications, such as bill of material explosions, recursive procedures are very effective.
Notes
- The RETURN-VALUE function provides the value returned by the most recently executed RETURN or THROW with options that set or clear a
return-value
.- If a procedure executing the RETURN statement is called asynchronously, the client can access the
return-value
and ERROR condition in the associated event procedure. For more information on event procedures, see OpenEdge Application Server: Developing AppServer Applications.See alsoCONSTRUCTOR statement, CREATE SERVER statement, DEFINE PROPERTY statement, FUNCTION statement, METHOD statement, ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, ON STOP phrase, RETURN-VALUE function, UNDO statement
OpenEdge Release 10.2B
|