Set the OptMsg global variable

The OptMsg global variable is defined in the sqlhdr.h header file.

After you set the OPTMSG environment variable to 1, you must set the OptMsg global variable to specify whether message chaining takes effect for each subsequent SQL statement. You can assign the following values to OptMsg:
1
This value enables message chaining for every subsequent SQL statement.
0
This value disables message chaining for every subsequent SQL statement.
With the OPTMSG environment variable set to 1, you must still set the OptMsg global variable to 1 to enable the message chaining. If you omit the following statement from your program, does not perform message chaining:
OptMsg = 1;
When you have set the OPTMSG environment variable to 1, you might want to disable message chaining for the following reasons:
  • Some SQL statements require immediate replies.

    See Restrictions on optimized message transfers for more information about these SQL statements. Re-enable the OPTMSG feature once the restricted SQL statement completes.

  • For debugging purposes

    You can disable the OPTMSG feature when you are trying to determine how each SQL statement responds.

  • Before the last SQL statement in the program to ensure that the database server processes all messages before the application exits. If OPTMSG is enabled, the message is queued up for the database server but it is not sent for processing.
To avoid unintended chaining, reset the OptMsg global variable immediately after the SQL statement that requires it. The following code fragment enables message chaining for the DELETE statement:
OptMsg = 1;
EXEC SQL delete from customer;
OptMsg = 0;
EXEC SQL create index ix1 on customer (zipcode);

This example enables message chaining because the execution of the DELETE statement is not likely to fail. Therefore, it can be safely chained to the next SQL statement. delays sending the message for the DELETE statement. The example disables message chaining after the DELETE statement so that flushes all messages that have been queued up when the next SQL statement executes. By disabling the message chaining after the DELETE, the code fragment avoids unintended message chaining. When unintended chaining occurs, it can be difficult to determine which of the chained statements has failed.

At the CREATE INDEX statement, sends both the DELETE and the CREATE INDEX statements to the database server.