SQL Programming Manual for Pascal

Error and Status Processing
HP NonStop SQL Programming Manual for Pascal528614-001
6-2
Checking the SQLCODE Variable
Declaring SQLCODE
Declare SQLCODE in your program as an integer variable:
VAR SQLCODE: INT16;
If you omit SQLCODE, the compiler generates an "undeclared identifier" error.
The SQLCODE variable must be declared within scope of the embedded SQL
statement that you will execute. To ensure SQLCODE is always in this scope, declare
SQLCODE as a global variable at the start of each module that contains embedded
SQL statements.
Checking SQLCODE
The following example inserts two column values into the PARTS table and checks
SQLCODE for errors.
{ Copy PEXTDECS for SQLCADISPLAY procedure, and }
{ Pascal extensions file for EXITPROGRAM procedure: }
IMPORT BEGIN
?SOURCE $ VOL.SUBVOL.PEXTDECS, NOLIST
?SOURCE $ VOL.SUBVOL.PASEXT, NOLIST
END ;
{ Variable Declarations: }
EXEC SQL BEGIN DECLARE SECTION ;
VAR IN_PARTS_REC: RECORD
IN_PARTNUM : INT16 ;
IN_PRICE : INT32 ;
IN_PARTDESC : FSTRING (18);
END ;
EXEC SQL END DECLARE SECTION ;
{ Declare SQLCA for use with SQLCADISPLAY procedure: }
EXEC SQL INCLUDE SQLCA ;
{ Declare SQLCODE for simple error checking }
VAR SQLCODE : INT16 ;
{ Code to handle errors and warnings:}
PROCEDURE HANDLE_ERRORS ;
BEGIN
SQLCADISPLAY( XADDR (SQLCA) );
EXEC SQL ROLLBACK WORK ;
EXITPROGRAM ;
END ; {HANDLE_ERRORS}
PROCEDURE HANDLE_WARNINGS;
BEGIN