SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)
Exception Handling and Error Conditions
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL—663854-005
13-11
SQL/MX Exception Condition Messages
EXEC SQL INSERT INTO sales.job (jobcode,jobdesc)
VALUES (:new_jobcode,:new_jobdesc);
if (SQLCODE == 0) { printf ("\nValues were inserted!");
EXEC SQL COMMIT WORK; }
else process_sqlcode();
...
void process_sqlcode(void)
{
printf("\nError or warning occurred! SQLCODE = %d",SQLCODE);
... /* Process the SQL error. */
}
* Global COBOL declarations
* Declare SQLCODE with data type PIC S9(9) COMP.
01 SQLCODE PIC S9(9) COMP.
...
* Set new_jobcode and new_jobdesc host variables.
EXEC SQL INSERT INTO sales.job (jobcode,jobdesc)
VALUES (:new-jobcode,:new-jobdesc)
END-EXEC.
IF SQLCODE = 0 DISPLAY "Values were inserted!"
EXEC SQL COMMIT WORK END-EXEC.
ELSE PERFORM 1000-PROCESS-SQLCODE.
...
1000-PROCESS-SQLCODE.
DISPLAY "Error or warning occurred! SQLCODE = " SQLCODE.
* Process the SQL error
...
SQL/MX Exception Condition Messages
NonStop SQL/MX reports exception condition messages within the MXCI, in SQL
preprocessor and compiler listings, and during the execution of embedded SQL
programs. You can obtain the messages for an SQL statement within a program by
accessing the SQL diagnostics area. For information on each message, see the
SQL/MX Messages Manual.
Note. You must declare SQLCODE anywhere in your program or declare SQLSTATE within a
Declare section. If you do not verify SQLSTATE, you must not declare SQLSTATE because
query execution requires string processing to return the SQLSTATE value. However, because
verifying SQLCODE is a deprecated operation, HP recommends that you verify SQLSTATE as
the means to detect exception conditions and to avoid compiler-generated warnings.
COBOL










