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

PRINT

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 9 ♥
E0399 Edition 8
E0897 Edition 7

The PRINT statement is used inside a procedure to store the content of user-defined strings, local variables, parameters, or built-in variables in the message buffer for display by ISQL or an application program.

Scope


Procedures only

SQL Syntax



  PRINT {'Constant'
         :LocalVariable
         :Parameter
         ::Built-inVariable};

Parameters


Constant

is a string literal.

LocalVariable

is a local variable declared within the procedure. Types and sizes are the same as for column definitions, except you cannot specify a LONG data type.

Parameter

is a parameter declared within the procedure.

Built-inVariable

is one of the following built-in variables used for error handling:

  • ::sqlcode

  • ::sqlerrd2

  • ::sqlwarn0

  • ::sqlwarn1

  • ::sqlwarn2

  • ::sqlwarn6

  • ::activexact

The first six of these have the same meaning that they have as fields in the SQLCA in application programs. Note that in procedures, sqlerrd2 returns the number of rows processed for all host languages. However, in application programs, sqlerrd3 is used in COBOL, Fortran, and Pascal, while sqlerr2 is used in C. ::activexact indicates whether a transaction is in progress or not. For additional information, refer to the application programming guides and to the chapter "Constraints, Procedures, and Rules."

Description


  • The results of any PRINT statements issued during the execution of a procedure are placed in the ALLBASE/SQL message buffer, and may be displayed like other messages. In an application program, they can be retrieved with SQLEXPLAIN upon exiting the procedure.

  • The message number 5000 is used for all PRINT statements.

Authorization


Anyone can issue the PRINT statement.

Examples



   CREATE PROCEDURE Process15 (PartNumber CHAR (16) NOT NULL) AS
      BEGIN
         DECLARE PartName CHAR(30);

         SELECT PartName INTO :PartName
         FROM PurchDB.Parts
         WHERE PartNumber = :PartNumber;
         IF ::sqlcode <> 0 THEN
             PRINT 'Row not retrieved.  Error code:';
             PRINT ::sqlcode;
         ELSE
             PRINT :PartName;
         ENDIF;
      END;

When an application program calls a procedure, you can include PRINT statements in the procedure for later retrieval by the application:

   IF ::sqlcode = 100 THEN
      PRINT 'Row was not found';
   ELSE
      PRINT 'Error in SELECT statement';
   ELSEIF ::sqlcode=0 THEN
      PRINT :PartName;
   ENDIF;

On returning from the procedure, use SQLEXPLAIN in a loop to extract all the messages generated by PRINT during the operation of the procedure.

In C:

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

In COBOL:

   IF SQLCODE IS NOT ZERO OR SQLWARN0 = "W"
      PERFORM M100-DISPLAY-MESSAGE
        UNTIL SQLCODE IS ZERO AND SQLWARN0 = "W".
   .
   .
   .
   M100-DISPLAY-MESSAGE.
      EXEC SQL SQLEXPLAIN :SQLMESSAGE END-EXEC.
      DISPLAY SQLMESSAGE.
   M100-EXIT.
      EXIT.




PREPARE


RAISE ERROR