Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 11: CICS Error Handling and Debugging


HANDLE ABEND

HANDLE ABEND is the safety net of CICS error handling. While RESP and HANDLE CONDITION deal with expected conditions, HANDLE ABEND catches the unexpected: abends. When the task is about to abend, CICS gives control to your abend handler instead, so you can write an error log, send a friendly message, and end the task cleanly.

What is HANDLE ABEND

  • Syntax: EXEC CICS HANDLE ABEND LABEL(label) END-EXEC. When an abend occurs later in the task, control branches to the label instead of terminating the task immediately.
  • Instead of LABEL you can code PROGRAM(name): CICS links to a separate abend-handling program. Or code CANCEL to remove a previous HANDLE ABEND.
  • The handler runs in a restricted state. Keep it short: log the error details, send a message to the terminal, and issue EXEC CICS RETURN or ABEND.
  • Code HANDLE ABEND at the very start of the program, before any command that could fail.

What the handler can and cannot do

  • The handler can read EIB fields such as EIBRESP, EIBTRNID, and the abend code, write to a TS queue or file log, and SEND a message to the terminal.
  • The handler should not try to resume normal processing. The task state is unreliable after an abend; the safe action is to log and end.
  • Some abends cannot be caught, for example abends forced by the operator with CEMT TASK PURGE. Do not rely on HANDLE ABEND for those.
  • A second abend inside the handler itself terminates the task immediately, so keep handler logic simple and well tested.

Example: logging the abend and ending cleanly

  • The example below sets the handler first, then does normal work. On abend it logs EIB details to a TS queue and tells the user:
    PROCEDURE DIVISION. 0000-MAIN. EXEC CICS HANDLE ABEND LABEL(9800-ABEND-HANDLER) END-EXEC. PERFORM 1000-DO-BUSINESS-LOGIC. EXEC CICS RETURN END-EXEC. 9800-ABEND-HANDLER. MOVE EIBTRNID TO LOG-TRNID. MOVE EIBTASKN TO LOG-TASKN. MOVE EIBRESP TO LOG-RESP. EXEC CICS WRITEQ TS QUEUE('ERRLOGQ') FROM(ERROR-LOG-REC) LENGTH(LENGTH OF ERROR-LOG-REC) END-EXEC. EXEC CICS SEND TEXT FROM('SYSTEM ERROR - PLEASE CONTACT SUPPORT') LENGTH(38) ERASE END-EXEC. EXEC CICS RETURN END-EXEC.

Cancelling HANDLE ABEND

  • To remove abend handling, issue EXEC CICS HANDLE ABEND CANCEL END-EXEC. Any later abend then terminates the task normally.
  • Use CANCEL when a section of code must abend loudly for debugging, for example during testing with CEDF.
  • If you XCTL to another program, set HANDLE ABEND again in the new program if you want continued protection.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant