Declaring SQLCODE as a standalone area

WARNING! Although SQLSTATE is preferred over SQLCODE and SQLCA, this version only fully supports SQLCODE. A future version will fully support 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 solely interested in return codes, consider using SQLCODE.

Despite SQLCODE’s faster execution speed, SQLSTATE is preferred over SQLCODE, which is supported for its compatibility with earlier versions of Embedded SQL.

NoteIn a future version, you will be advised to use SQLSTATE instead of SQLCODE for receiving status results.

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

long SQLCODE;
exec sql open cursor pub_id;
     while (SQLCODE == 0)
     {
     exec sql fetch pub_id into :pub_name;

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 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.