SQL/MP Programming Manual for COBOL

SQL/MP System Procedures
HP NonStop SQL/MP Programming Manual for COBOL529758-003
5-11
Generating Meaningful Messages
As shown in Example 5-2 on page 5-10, the messages sent to the HOMETERM
contain neither the internal location where the error was encountered nor the statistics
and cost of the SQL statement. Usually, this information is not important and can be
omitted to reduce the number of error lines.
Consider an SQL constraint that is violated during the update, causing this message to
be sent to HOMETERM:
SQLCA display of SQL statement at SAMPLE.#5141.854 process \AAA.$BBB
ERROR from SQL [-8233] Constraint Number 2 violated on base table T1.
Upon receiving this message, the database administrator can query the catalog
through SQLCI to display the actual constraint predicate that was violated. This
information is in the catalog CONSTRNT table. For this particular error, it is the second
entry for the table T1.
Generating Meaningful Messages
The previous error message illustrates why it is sometimes difficult for a program to
generate meaningful messages for display at a terminal. For example, consider the
steps required for a program to generate a message such as “DATA FOR colname
EXCEEDS LIMITS” that identifies the specific column in error:
1. The error routine might call SQLCA_TOBUFFER2_ (instead of
SQLCA_DISPLAY2_) so the program can examine the buffer to retrieve the SQL
error message with the constraint number and the table name.
2. If the program has read access to the catalog tables, it could develop a query
against the CONSTRNT table by using the constraint number and table name
returned by SQLCA_TOBUFFER2_ to retrieve more information about the
constraint.
3. The program could then generate a message using the constraint information from
the CONSTRNT table and return this message to the terminal.
SQLCA_TOBUFFER2_
The SQLCA_TOBUFFER2_ procedure writes to a buffer the error or warning
messages that SQL/MP returns to the application program. The buffer is a record area
declared in the Working-Storage or Extended-Storage Section.
The information returned to the buffer can originate from these subsystems or system
components:
SQL/MP
NonStop OS
File system
Disk process (DP2)
FastSort program (SORTPROG process)
Sequential I/O (SIO) procedures