Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

How do I handle DEADLOCKs in CICS/DB2 on-line applications?

How do I handle DEADLOCKs in CICS/DB2 on-line applications? Typically, I would like to report an error only after a certain number of tries. Can this be handled by altering CICS settings? How do I handle this programmatically?

I assume you have read the chapter on "Handling deadlocks in the CICS DB2 environment" in the CICS DB2 Guide (SC34-6014 for CICS TS V2.2, SC33-1939 for CICS TS V1.3).

There is no way to configure CICS to retry multiple times before reporting the error.

There are two way you can handle this programmatically. The first is by changing the application to respond to the -911 or -913 SQL response code that DB2 returns to the program that has been chosen to be sacrificed to relieve the deadlock. The application could (after rolling back any changes if necessary) start again from the beginning, keeping a count of retries so that the application can give up after a certain number of tries.

Alternatively you could exploit the CICS transaction restart capability. This is described in detail in the CICS Customization Guide (SC34-5989 for CICS TS V2.2, SC33-1683 for CICS TS V1.3). In short, if the transaction is defined with RESTART(YES) then CICS invokes the DFHREST user replaceable module if the transaction abends. The user replaceable module determines if the transaction is to be restarted, usually based on the abend code. It is advisable to have unique abend codes for the abends that are caused by retryable situations, such as deadlocks, so that DFHREST can easily determine if there is any chance that the transaction would succeed at a second attempt. If DFHREST indicates that the transaction is to be restarted CICS will complete the abend of the failing task and then attach a new transaction instance with the same principal facility and input message as the initial instance.The interface to DFHREST includes a retry count so that DFHREST can avoid an infinite loop of abending tasks. There are some restrictions that result in this technique not being applicable for all applications so you will need to read the documentation carefully. CICS supplies a sample DFHREST that provides a retry capability for DBCTL and VSAM deadlocks and which should help you write your own version.

Dig Deeper on IBM system z and mainframe systems