Exception Handling in CICS

Exception handling

It is one of the core concept in CICS coding. Programmer should have knowledge on exception handling methods for effective use of these methods while developing any program. This topic gives various types of exception handling and usage of each one in detail.

By default CICS manages the exceptions internally and ends programs accordingly but this can be nullified or routed by specifying either NOHANDLE or RESP options in CICS commands. This facilitates the programmer to take appropriate actions in different scenarios.

Using RESP & RESP2
Every CICS-EXEC command gives a response back after execution and Using RESP gives the user the ability to validate the response received and proceed further.RESP option should be coded in the command itself as shown below.

EXEC CICS RECEIVE MAP(MAP01)
           MAPSET(MAP01S)
           INTO(WS-MAP)
           RESP(WS-RESPONSE)
END-EXEC

In EIB copy book, EIBRESP and EIBRESP2 are the two important fields to know the error details. EIBRESP stores the basic error response where as EIBRESP2 stores the additional error information and by carefully knowing the meaning of these two fields gives the better understanding of the abend.

There are three commands which can be used to change the way the exceptions are being managed. Those are HANDLE CONDITION, IGNORE CONDITION and HANDLE ABEND. If any of these HANDLE or IGNORE conditions are specified as the first ones in procedure division, then these are ones that execute first after any exception.

Handle Abend

This is to route any abnormal conditions happened with the program. This para routes those errors to the specified para or program given.Also it deactivates or reactivates all the prev. HANDLEConditions.
Syntax –

EXECE CICS
      HANDLE ABEND
      PROGRAM(program name)
      LABEL(para name)
      CANCEL|RESET
END-CICS

Program                    –> Gives control to the specified program
LABLE                       –> gives control to the paragraph specified
CANCEL & RESET  –> These are mutually exclusive. CANCEL is to cancel the Active HANDLE ABEND requests where as RESET is to activate the previously cancelled handle abend.
When a TASK terminates abnormally, CICS looks for active abend exits starting the error location to the higher levels from there and gives control to the first found active exit.

Ex:

EXECE CICS
      HANDLE ABEND
      LABLE(ERR-PARA)
END-CICS
.
.
.
--> Abend occurred here so the control goes to ERR-Para
.
.

ERR-PARA
** send error details on to the screen
MOVE 'ABEND IN TRANSACTION XXXX' TO WS-ERROR-MSG
EXEC CICS SEND TEXT
          FROM (WS-ERROR-MSG)
          LENGTH(100)
          ERASE
END-EXEC

Handle Condition

This is to route the CICS command exceptions to the specified para. Conditions like MAPFAIL. program ID error etc.It does not handle program abends like soc4, sco7 etc..
Ex:

EXEC CICS
     HANDLE CONDITION
     MAPFAIL(MAPFAIL-PARA)
     PGMIDERR(ID-ERR-PARA)
     ERROR(COMMON-ERROR-PARA)
END-EXEC

Here Exceptions other than MAPFAIL and PGMIDERR are routed to COMMON-ERROR-PARA.

IGNORE CONDITION

It is to instruct the CICS that any exceptions specified in the ‘IGNORE CONDITION’ should be ignored and the program should give control to the next executable line of this condition.This is exactly in contrast to the HANDLE CONDITION command, which specifies that control passes to a specified label when a specific condition occurs.
Ex:

EXECCICS
     IGNORE CONDITION
     MAPFAIL
END-EXEC

If there are any MAPFAIL conditions, program ignores that condition and progresses further but if there is any HANDLE CONDITION command on the same MAPFAIL after the IGNORE condition then Ignore will be overridden by HANDLE condition.An IGNORE CONDITION command for a given condition applies only to the program you put it in and it remains active while the program is running, or until a later HANDLE CONDITION command that names the same condition.

IGNORE CONDITION ERROR is to handle any unspecified exceptions which do not have any specific error handling(like HANDLE conditions )logic is coded.

As a common practice to handle the exceptions in a  program, an IGNORE CONDITION ERROR is coded as the first command in procedure division followed by a HANDLE ABEND/CONDITION.

NOHANDLE —> This is to override the HANDLE condition commands coded in the program. If for any specific CICS command, HANDLE condition needs to be ignored then NOHANDLE is coded. RESP is also deactivates the HANDLE CONDITION command.

HANDLE AID
This is to handle the AID keys received and  it is effective through out the program and invoked after every RECEIVE Command.

Example-1:

EXECCICS
     HANDLE AID
     DFHENTR (PARA1)
     DFHPF1 (PARA2)
     ANYKEY (PARA3)
END-EXEC

Example-2:

EXEC CICS HANDLE AID
     PA1(LAB1)
     ANYKEY(LAB2)
     PF10
END-EXEC

– HANDLE AID command that specifies one label for the PA1 key
– Second label for CLEAR, PA2, PA3, and all the function keys except PF10.
– If a PF10 AID is received, or ENTER is pressed, control returns to the application program at the instruction immediately following the input command.

Add a Comment

Your email address will not be published. Required fields are marked *