SQL/MP Programming Manual for COBOL

Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL529758-003
9-20
Returning Information From the SQLCA
Summary of Error Processing Recommendations
This list summarizes the recommendations described in this subsection for processing
errors.
Use WHENEVER directives to test for SQL errors, warnings, and other conditions.
Each WHENEVER directive should refer to a common error handling routine.
Develop common error handling routines that can be saved in a source library and
copied with a COBOL COPY command or an COBOL SOURCE directive.
Include a call to the SQLCA_TOBUFFER2_ or to SQLCA_DISPLAY2_
procedure in any error routine that logs or displays the errors.
Consider using two sets of common error handling routines: one for
development and one for production. In the development routine, specify a
breakpoint or a call to the Inspect program.
Establish meaningful messages to be returned to the operator, such as:
A not-found condition returns Requested Data Does Not Exist.
A duplicate condition returns Data Cannot Be Inserted - Already Exists.
A file-system error returns File-System Error error occurred. Use
SQLCAFSCODE to determine the file-system error number.
An SQL error returns SQL Error error occurred.
Create an SQL table to save the error messages. Use SQLCA_TOBUFFER2_ to
return the error code, message text, program line number, and other information
you save in the error table:
Put a timestamp, terminal ID, SQL error, and file-system error in the first
columns of the table row to be used as search criteria for later retrieval.
Write the error information to the last columns of the table row.
Specify parameters in the calls to SQLCA_TOBUFFER2_ to reduce the
number of error lines generated for each error by suppressing statistics and the
internal error location and by setting the prefix to a single blank character.
Specify parameters in the calls to SQLCA_TOBUFFER2_ to generate error
lines of 80 characters each to match the line length that SQLCI displays.
Define the table columns that are to receive the error information as multiples
of 80, but not greater than 240, characters. This size prevents wraparound
because SQLCI displays large columns as 80-character lines and prevents
truncation because SQLCI displays a maximum of 255 characters per column.
In summary, retrieve the error information in 80-byte error lines and define two,
three, or four text columns of 240 bytes each in the SQL error table.
Use SQLCI to query and display the error table.