About this task
You can declare the SQLCA in your application program
so that the database manager can return information to your application.
When you preprocess your program, the database
manager inserts
host language variable declarations in place of the INCLUDE SQLCA
statement. The system communicates with your program using the variables
for warning flags, error codes, and diagnostic information.
After
executing each SQL statement, the system returns a return code in
both SQLCODE and SQLSTATE. SQLCODE is an integer value that summarizes
the execution of the statement, and SQLSTATE is a character field
that provides common error codes across IBM®'s
relational database products. SQLSTATE also conforms to the ISO/ANS
SQL92 and FIPS 127-2 standard.
Note: FIPS 127-2 refers to Federal
Information Processing Standards Publication 127-2 for Database Language
SQL. ISO/ANS SQL92 refers to American National Standard Database
Language SQL X3.135-1992 and International Standard ISO/IEC
9075:1992, Database Language SQL.
Note that if SQLCODE
is less than 0, it means an error has occurred and the statement has
not been processed. If the SQLCODE is greater than 0, it means a warning
has been issued, but the statement is still processed.
For a DB2® application written in C or
C++, if the application is made up of multiple source files, only
one of the files include the EXEC SQL INCLUDE SQLCA statement to avoid
multiple definitions of the SQLCA. The remaining source files must
use the following lines:
#include "sqlca.h"
extern struct sqlca sqlca;
To declare the SQLCA,
code the
INCLUDE SQLCA statement in your program
as follows:
What to do next
If your application must be compliant with
the ISO/ANS SQL92 or FIPS 127-2 standard, do not use the statements
previously shown or the INCLUDE SQLCA statement.