Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 22 Coding SQL Access Statements : Error Checking and Handling

Error Checking and Handling
Error Checking
After every SQL statement, check for errors. TIBCO Object Service Broker returns error information in the following variables:
0 if the statement completed successfully, 100 if it reached the end of the table, or -1 if an error occurred.
If you are using SQLCA, the variable SQLERRMC contains either an SQL message if an SQL error occurred or a TIBCO Object Service Broker error message.
Error Handling Status Variables
If SQLCA is present, it indicates that the Sqlcode variable is also present and error information must be relayed through the provided variables.
The Sqlstate status variable can be used in place of, or in addition to, the Sqlcode and SQLCA. It is a string of five characters that relays error codes. The following table shows the possible error codes and their explanations:
You must ensure that you use the correct level number and picture clause: the preprocessor scans the host variables in the Declare section to see if Sqlstate is mentioned. If so, it updates all successes/errors through it, in addition to Sqlcode (if it was also mentioned in an Include SQLCA statement or on its own).
The Sqlcode status variable can be used on its own or together with Sqlstate. If SQLCA is used, there is no need to declare Sqlcode. If it is declared with SQLCA, the COBOL compiler can pick up two declarations and report it as an error at compile time. If you use Sqlcode, you must ensure that the proper level number and picture clause are used.
Any of these three methods can be used to get error information but the default assumption is that Sqlcode was properly declared. If this is not true (that is, Sqlcode was not declared), the compiler detects an undefined variable and reports it to you at compile time.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved