DB2 Server for VSE & VM: Application Programming


Handling SQL Errors

There are two ways to declare the return code structure (called SQLCA):

  1. You can write the following statement in your source program:
       EXEC SQL INCLUDE SQLCA;
    

    The preprocessor replaces this with the declaration of the SQLCA structure.

  2. You may declare the SQLCA structure directly, as shown in Figure 127.

    Figure 127. SQLCA Structure (in PL/I)

       DCL 1 SQLCA,
             2 SQLCAID CHAR(8),
             2 SQLCABC BIN FIXED(31),
             2 SQLCODE BIN FIXED(31),
             2 SQLERRM CHAR(70) VAR,
             2 SQLERRP CHAR(8),
             2 SQLERRD (6) BIN FIXED(31),
             2 SQLWARN,
               3 SQLWARN0 CHAR(1),
               3 SQLWARN1 CHAR(1),
               3 SQLWARN2 CHAR(1),
               3 SQLWARN3 CHAR(1),
               3 SQLWARN4 CHAR(1),
               3 SQLWARN5 CHAR(1),
               3 SQLWARN6 CHAR(1),
               3 SQLWARN7 CHAR(1),
               3 SQLWARN8 CHAR(1),
               3 SQLWARN9 CHAR(1),
               3 SQLWARNA CHAR(1),
             2 SQLSTATE CHAR(5);
    

The SQLCA must not be declared within the SQL declare section. The meanings of the fields in the SQLCA are discussed in the DB2 Server for VSE & VM SQL Reference manual.

You may find that the only variable in the SQLCA you really need is SQLCODE. If this is the case, declare just the SQLCODE variable, and invoke NOSQLCA support at preprocessor time.

The number of SQLCODE declarations is not limited by the preprocessor. If a stand-alone SQLCODE is specified, the code inserted by the preprocessor into the PL/I code to expand an EXEC SQL statement will refer to the address of that SQLCODE. The PL/I compiler determines if multiple declarations within a program section are not acceptable. In addition, the PL/I compiler determines which region of the code an SQLCODE declaration refers to.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]