ALLBASE/SQL Reference Manual (36216-90216)

Chapter 11 487
SQL Statements E - R
RETURN
RETURN
The RETURN statement permits you to exit from a procedure with an optional return code.
Scope
Procedures only
SQL Syntax
RETURN [
ReturnStatus
];
Parameters
ReturnStatus
is an integer value that is returned to the caller. The syntax is:
{INTEGER
:
LocalVariable
:
ProcedureParameter
::
Built-inVariable
}
Description
The RETURN statement causes the execution of the procedure to halt and causes control
to return to the invoking user, application program, or rule. When it returns to a rule,
the value of
ReturnStatus
is ignored.
The RETURN statement is optional within a procedure.
If the procedure terminates without executing a RETURN statement, the
ReturnStatus
will be 0.
You can only access
ReturnStatus
from an application program. Call the procedure
from the program using an integer host variable for
ReturnStatusVariable
if you
wish to test the
ReturnStatus
.
Example
CREATE PROCEDURE Process10 (PartName CHAR(20) NOT NULL,
Quantity INTEGER NOT NULL) AS
BEGIN
INSERT INTO SmallOrders VALUES (:PartName, :Quantity);
IF ::sqlcode <> 0 THEN
GOTO Errors;
ENDIF;
RETURN 0;
Errors: PRINT 'There were errors.';
RETURN 1;
END
Call the procedure using a ReturnStatusVariable named Status:
EXECUTE PROCEDURE :Status = Process10 ('Widget', 10)