HPlogo ALLBASE/SQL Reference Manual > Chapter 11 SQL Statements E - R

RETURN

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 9 ♥
E0399 Edition 8
E0897 Edition 7

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)

On returning from the procedure, test SQLCODE and Status both to determine whether an error occurred inside the procedure.

   if(sqlca.sqlcode==0)
    if(Status!=0) do {
                EXEC SQL SQLEXPLAIN :SQLMessage;
                   printf("%s\n",SQLMessage);
                 } while (sqlwarn[0]=='W');




RESET


REVOKE