SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Exception Handling and Error Conditions
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
13-7
SQL/MX Exception Condition Messages
...
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.
Viewing the SQL Messages
To view a list of all SQL messages, see the appropriate messages manual.
The message key is a sequential SQL/MX message number that is returned
automatically by NonStop SQL/MX when an error condition occurs. For example, this
error message might be displayed within your application development tool while it is
preparing an embedded SQL program:
*** ERROR[1000] A syntax error occurred.
This message number is the SQLCODE value (without the sign). You can view the
message for ERROR[1000]:
COBOL