Example: handling errors by using CICS HANDLE

The following example shows the use of CICS HANDLE in COBOL programs.

Program A has a CICS HANDLE CONDITION command and program B has no CICS HANDLE commands. Program A calls program B; program A also calls nested program A1. A condition is handled in one of three scenarios.

(1)
CBLPSHPOP(ON): If the CICS READ command in program B causes a condition, the condition is not handled by program A (the HANDLE specifications are suspended because the run time performs a CICS PUSH HANDLE). The condition turns into a transaction abend.
(2)
CBLPSHPOP(OFF): If the CICS READ command in program B causes a condition, the condition is not handled by program A (the run time diagnoses the attempt to perform cross-program branching by using a CICS HANDLE command with the LABEL option). The condition turns into a transaction abend.
(3)
If the CICS READ command in nested program A1 causes a condition, the flow of control goes to label ERR-1, and unpredictable results occur.

***********************************************************
*  Program A                                              *
***********************************************************
 ID DIVISION.
 PROGRAM-ID. A.
 . . .
 PROCEDURE DIVISION.
     EXEC CICS HANDLE CONDITION
               ERROR(ERR-1)
               END-EXEC.
     CALL 'B' USING DFHEIBLK DFHCOMMAREA.
     CALL 'A1'.
     . . .
 THE-END.
     EXEC CICS RETURN END-EXEC.
 ERR-1.
 . . .
* Nested program A1.
 ID DIVISION.
 PROGRAM-ID. A1.
 PROCEDURE DIVISION.
     EXEC CICS READ              (3)
               FILE('LEDGER')
               INTO(RECORD)
               RIDFLD(ACCTNO)
               END-EXEC.
 END PROGRAM A1.
 END PROGRAM A.
*
***********************************************************
*  Program B                                              *
***********************************************************
 ID DIVISION.
 PROGRAM-ID. B.
 . . .
 PROCEDURE DIVISION.
     EXEC CICS READ              (1)  (2)
               FILE('MAINFILE')
               INTO(RECORD)
               RIDFLD(ACCTNO)
               END-EXEC.
     . . .
 END PROGRAM B.