Two samples are provided that demonstrate how IBM MQ can coordinate both IBM MQ updates and database updates within the same unit of work.
These samples are:
AMQSXAS0 (in C) or AMQ0XAS0 (in COBOL), which updates a single database within an IBM MQ unit of work.
AMQSXAG0 (in C) or AMQ0XAG0 (in COBOL), AMQSXAB0 (in C) or AMQ0XAB0 (in COBOL), and AMQSXAF0 (in C) or AMQ0XAF0 (in COBOL), which together update two databases within an IBM MQ unit of work, showing how multiple databases can be accessed. These samples are provided to show the use of the MQBEGIN call, mixed SQL and IBM MQ calls, and where and when to connect to a database.
Figure 1 shows how the samples provided are used to update databases:
The programs read a message from a queue (under syncpoint), then, using the information in the message, obtain the relevant information from the database and update it. The new status of the database is then printed.
The program logic is as follows:
Use the name of the input queue from the program argument
SQL cursors are used in the samples, so that reads from the databases (that is, multiple instances) are locked while a message is being processed, allowing multiple instances of these programs to run simultaneously. The cursors are explicitly opened, but implicitly closed by the MQCMIT call.
The single database sample (AMQSXAS0 or AMQ0XAS0) has no SQL CONNECT statements and the connection to the database is implicitly made by IBM MQ with the MQBEGIN call. The multiple database sample (AMQSXAG0 or AMQ0XAG0, AMQSXAB0 or AMQ0XAB0, and AMQSXAF0 or AMQ0XAF0) has SQL CONNECT statements, as some database products allow only one active connection. If this is not the case for the database product, or if we are accessing a single database in multiple database products, the SQL CONNECT statements can be removed.
The samples are prepared with the IBM Db2 database product, so you might need to modify them to work with other database products.
The SQL error checking uses routines in UTIL.C and CHECKERR.CBL supplied by Db2. These must be compiled or replaced before compiling and linking.
Note: If we are using the Micro Focus COBOL source CHECKERR.MFC for SQL error checking, we must change the program ID to uppercase, that is CHECKERR, for AMQ0XAS0 to link correctly.