An example of exception handling in COBOL
The following example is a typical function which could be used to receive a BMS map and to cope with exception conditions.
03 RESPONSE PIC S9(8) BINARY.
03 EXITKEY PIC X.
EXEC CICS RECEIVE MAP(MAPNAME)
MAPSET('ACCOUNT')
INTO(MAP)
RESP(RESPONSE)
END-EXEC.
IF (RESPONSE NOT = DFHRESP(NORMAL)) AND
(RESPONSE NOT = DFHRESP(MAPFAIL))
MOVE DFHCLEAR TO EXITKEY
ELSE
MOVE EIBAID TO EXITKEY
IF RESPONSE = DFHRESP(NORMAL)
GO TO MODIFYMAP
END-IF
END-IF.
MODIFYMAP.
MAPNAME is the variable which contains the name of the map which is to be received.
The RESP value is returned in RESPONSE. RESPONSE is declared as a fullword binary variable in the data section.
The EXEC CICS statement asks for a map of the name given by MAPNAME , of the mapset ACCOUNT, to be read, with the value of the condition being held by the variable RESPONSE.
The condition handling is done by using IF … statements. If the condition is neither NORMAL nor MAPFAIL the program behaves as if the user had cleared the screen.
If the condition is either NORMAL or MAPFAIL the program saves the value of the key which the user pressed to exit the screen in EXITKEY. In addition, if the condition is NORMAL, the program branches to MODIFYMAP to perform some additional function.