Previous Topic: Terminating a TaskNext Topic: Performing Abend Routines


Handling db-key Deadlocks

You can include logic in your program that is invoked if your run unit is terminated because of a db-key deadlock. This enables your program to maintain the terminal session and save any data that was previously entered on the screen.

At that point, your program can do one of the following:

What Happens When a Deadlock Occurs

When a run unit is terminated because its request would cause a deadlock condition, the DBMS:

  1. Rolls back the database transaction and terminates the run unit. The rollback operation releases all locks held by the aborted run unit.
  2. Writes the following message to the log:
    TASK: task-code PROG: program-name
    SUBS: subschema-name SSCSTAT: subschema-status
    RUN-UNIT run-unit-id ROLLED OUT.'
    
  3. Returns control to the issuing task with a status code of nn29, which indicates that a deadlock has occurred.

What To Do

You can continue a terminal session in the event of a deadlock by having your program resubmit a transaction in response to a minor status code of nn29. How you do this is largely a site-specific decision. Typically, you resubmit a transaction in one of two ways:

Automatically Restarting the Run Unit

If your program automatically restarts the run unit and retries the transaction, it must:

  1. Rebind the run unit by:
    1. Reinitializing the ERROR-STATUS field in the IDMS communications block to the value 1400
    2. Issuing the appropriate BIND/READY sequence
  2. Reestablish the appropriate currencies before retrying the transaction that originally caused the deadlock.

If You Don't Check for the Minor Code

If your program fails to check for a minor code of nn29, you can expect the following results:

'COBOL'. COBOL programs must redefine the ERROR-STATUS field of the IDMS communications block to access the minor code value.

Example of Resubmitting the Transaction

The program excerpt below informs the user of a database minor code of nn29 and requests that the transaction be resubmitted:

 WORKING-STORAGE SECTION.
 01  SUBSCHEMA-CTRL.
    03  PROGRAM-NAME           PIC X(8) VALUE SPACES.
    03  ERROR-STATUS           PIC X(4) VALUE '1400'.
           .
           .
    03 SUBSCHEMA-CTRL-END      PIC X(4).
 01  SSC-REDEF REDEFINES SUBSCHEMA-CTRL.
    03  FILLER                 PIC X(8) VALUE SPACES.
    03  ERRSTAT-REDEF.
      05  ERRSTAT-MAJ          PIC XX.
      05  ERRSTAT-MIN          PIC XX.
          88 DEADLOCK        VALUE '29'.
    03  FILLER                 PIC X(292).
*
 01  MESSAGES.
     05 DBKEY-DEADLOCK-MESSAGE  PIC X(80) VALUE
        'REQUESTED RECORD IN USE.  PLEASE RESUBMIT TRANSACTION'.
 .
 .
 .
 PROCEDURE DIVISION.
 .
 .
 .
 IDMS-ABORT.
     IF DEADLOCK
       THEN
          MODIFY MAP TSKMAP01 TEMPORARY
             FOR ALL FIELDS NOMDT
          MAP OUT USING TSKMAP01
             MESSAGE IS DBKEY-DEADLOCK-MESSAGE LENGTH 80
          DC RETURN NEXT TASK CODE 'UPDATASK'.
 IDMS-ABORT-EXIT.
     EXIT.
     COPY IDMS IDMS-STATUS.
******************************************************************
 IDMS-STATUS                                             SECTION.
********************* IDMS-STATUS FOR IDMS-DC ********************
         IF DB-STATUS-OK GO TO ISABEX.
         PERFORM IDMS-ABORT.
         MOVE ERROR-STATUS TO SSC-ERRSTAT-SAVE
         MOVE DML-SEQUENCE TO SSC-DMLSEQ-SAVE
         SNAP FROM SUBSCHEMA-CTRL TO SUBSCHEMA-CTRL-END
                    ON ANY-STATUS NEXT SENTENCE.
         ABEND CODE SSC-ERRSTAT-SAVE
                    ON ANY-STATUS NEXT SENTENCE.
 ISABEX. EXIT.
 DMCL-DC-GEN-GOBACK SECTION.
     GOBACK.