Declaring SQLCODE as a standalone area

NoteAlthough SQLSTATE is preferred over SQLCODE and SQLCA, this version of the precompiler supports only SQLCODE. A future version will fully support both SQLCA and SQLSTATE.

As an alternative to creating a SQLCA, use SQLCODE independently. It contains the return code of the most recently executed SQL statement. The benefit of declaring SQLCODE as a standalone area is that it executes code faster. If you have no need to review the other information that SQLCA holds and are interested only in return codes, consider using SQLCODE.

Despite SQLCODE’s faster execution speed, SQLSTATE is preferred over SQLCODE because SQLCODE is a deprecated feature that is compatible with earlier versions of Embedded SQL.

WARNING! Do not declare SQLCODE within a declare section.

Following is an example of declaring SQLCODE as a standalone area:

01  SQLCODE S9(9)    COMP.
 exec sql open cursor pub_id   end-exec.
PARAGRAPH-1:
    exec sql fetch pub_id into :PUB_NAME  end-exec.
 IF SQLCODE = 0 GOTO PARAGRAPH-1.

For details on debugging any errors SQLCODE indicates, see Chapter 8, “Handling Errors.”

Table 3-2 displays SQLCODE values:

Table 3-2: SQLCODE values

Value

Description

0

Statement executed successfully.

-n

Error occurred. See Server-Library or Client-Library error messages. -n represents the number associated with the error or exception.

+100

No data exists, no rows left after fetch, or no rows met search condition for update, delete, or insert.