RETURN statement

Leaves the local or remote procedure, user-defined function, ON trigger, method of a class, class constructor or destructor, or property accessor, and returns to the caller. If there is no caller, returns to the Procedure Editor or Progress Developer Studio for OpenEdge tool.

For more information on remote procedures, see OpenEdge Application Server: Developing AppServer Applications.

Syntax

RETURN 
    [return-value|
       ERROR [error-return-value|error-object-expression]|
       NO-APPLY ]
return-value

This has different behavior depending on whether a value can be returned from the current context. From contexts that don’t return a value, this is used to set RETURN-VALUE.

For a procedure or ON trigger block, the value is used to set RETURN-VALUE:

  • If return-value is specified, it must be a CHARACTER expression.
  • If return-value is not specified, RETURN-VALUE is set to the empty string ("").
  • To retrieve the return-value, access the RETURN-VALUE function from the caller.
For a user-defined function, non-VOID method, or property accessor:
  • Return-value must be specified.
  • Return-value must be an expression whose data type matches the return type of the function, method, or property; 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 entry for more information).
  • To retrieve the return-value from the caller, simply reference the function or method call in an expression.

For a VOID method, you cannot set a return-value.

ERROR
Causes an ERROR condition in the calling block.

You cannot use the ERROR option in a user-interface trigger block to raise ERROR outside of the trigger block.

RETURN ERROR in a user-defined function does not raise ERROR in the caller. Instead, it sets the target variable of the function to the Unknown value (?). See OpenEdge Development: ABL Error Handling for more information.

error-return-value
Any CHARACTER expression.

To retrieve the return value in the caller, catch the Progress.Lang.AppError using a CATCH statement and obtain the ReturnValue property of the AppError. Alternatively, the caller can access the RETURN-VALUE function.

If you do not specify either error-return-value or error-object-expression, both the RETURN-VALUE function as well as the AppError ReturnValue property is set to the empty string("").

error-object-expression

An expression that resolves to a specific error object. It must be an object derived from Progress.Lang.ProError or an object of a class that implements Progress.Lang.Error. The compiler generates an error if these rules are not met. Note that the only error object you can instantiate directly is a Progress.Lang.AppError object or a subclass.

RETURN ERROR error-object-expression immediately returns to the caller before throwing the error object.

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 a return-value or error object.

Examples

The following code demonstrates using RETURN in a user-defined function.

DEFINE VARIABLE dTemp AS DECIMAL NO-UNDO INITIAL 0.
 
FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL):
    RETURN (dCelsius * 1.8) + 32.
END.

MESSAGE dTemp "degrees Celsius is" CtoF(dTemp) "degrees Fahrenheit." SKIP    
    VIEW-AS ALERT-BOX.

Output:

0 degrees Celsius is 32 degrees Fahrenheit.

The following code illustrates using RETURN ERROR in a user-defined function.

DEFINE VARIABLE iFuncReturn AS INTEGER INITIAL 99 NO-UNDO.

FUNCTION ErrorTest RETURNS INTEGER:
    RETURN ERROR.
END FUNCTION.

ASSIGN iFuncReturn = ErrorTest().
IF iFuncReturn EQ ? THEN
    MESSAGE "Error in user-defined function." view-as alert-box.

Output:

Error in user-defined function.

The following code demonstrates using RETURN ERROR with an error object.

DEF VAR ix AS INT.

RUN proc NO-ERROR.  
IF ERROR-STATUS:ERROR THEN
DO:
    DO ix = 1 TO ERROR-STATUS:NUM-MESSAGES: /* this will be 2 */           
        MESSAGE ERROR-STATUS:GET-MESSAGE(ix) ERROR-STATUS:GET-NUMBER(ix).
    END.            
END.

PROCEDURE proc:
    DEFINE VAR err AS PROGRESS.Lang.AppError.
        
    err = NEW PROGRESS.Lang.AppError("The car cannot be rented",1).
    err:AddMessage ("No driver's license was provided", 98).

    RETURN ERROR err.
END.

Output:

The car cannot be rented 1
No driver's license was provided 98

Notes

See also

CONSTRUCTOR statement, DEFINE PROPERTY statement, ERROR-OBJECT attribute, FUNCTION statement, METHOD statement, ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, ON STOP phrase, RETURN-VALUE function, UNDO statement