ALLBASE/SQL Reference Manual (36216-90216)

472 Chapter11
SQL Statements E - R
PRINT
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);
}