Module 9: CICS DB2 Integration
DB2 Connection
The DB2 connection is the link between one CICS region and one DB2 subsystem. It is defined once and shared by every transaction in the region.
What the CICS DB2 connection is
- The connection attaches the CICS region to a DB2 subsystem so programs can issue SQL.
- It is defined by a DB2CONN resource definition. Only one DB2CONN is active in a region at a time.
- CICS normally connects at startup. It can also be connected and disconnected while the region runs.
- All SQL from the region flows through this connection, running on DB2 threads.
Key DB2CONN attributes
- DB2ID - the four-character name of the DB2 subsystem to connect to, for example DB2P.
- CONNECTERROR - what happens to transactions if the connection fails: abend them, return a SQLCODE, or queue them in a pool.
- STANDBYMODE - set to RECONNECT so CICS automatically reconnects when DB2 comes back up.
- MSGQUEUE1 - the transient data queue (default CDB2) where DB2 connection messages are written.
- ACCOUNTREC - controls DB2 accounting records: none, transaction id, user id, or UOW level detail.
- COMAUTHID / COMMAUTH - authority used when CICS connects to DB2.
Connecting and disconnecting
- Use CEMT INQUIRE DB2CONN to see the connection status: CONNECTED or NOTCONNECTED.
- Use CEMT SET DB2CONN CONNECTED to connect, or CEMT SET DB2CONN NOTCONNECTED to disconnect.
- Disconnecting while transactions are using DB2 waits for, or ends, the in-flight units of work depending on the options.
- Before planned DB2 maintenance, disconnect cleanly rather than letting transactions fail.
Example
- A DB2CONN definition created with RDO (resource definition online).
- CREATE DB2CONN(MYCONN) DESCRIPTION('CICS TO DB2 PRODUCTION CONNECTION') DB2ID(DB2P) CONNECTERROR(SQLCODE) MSGQUEUE1(CDB2) STATSQUEUE(CDB2) STANDBYMODE(RECONNECT)
- With CONNECTERROR(SQLCODE), a transaction that loses the connection gets a negative SQLCODE instead of abending, so the program can handle it.
