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

Module 11: CICS Error Handling and Debugging


HANDLE CONDITION

HANDLE CONDITION is a single statement that sets up error handling for every CICS command that follows it. Instead of coding RESP on each command, you list the conditions you care about and give a paragraph or section name for each. When any later command raises one of those conditions, control branches to your label automatically.

What is HANDLE CONDITION

  • Syntax: EXEC CICS HANDLE CONDITION condition(label) ... END-EXEC. You can list several conditions in one statement.
  • It stays in effect from the point it executes until the task ends, or until you change it. It is not limited to the next command.
  • The label must be a paragraph or section name in the same program.
  • A special condition name ERROR catches any exceptional condition not listed separately - a useful catch-all at the end of the list.

Scope and overriding

  • A later HANDLE CONDITION for the same condition replaces the earlier one. The most recent one wins.
  • Coding a command with its own RESP option bypasses HANDLE CONDITION for that command only.
  • To cancel handling for a condition, issue HANDLE CONDITION for it without a label: EXEC CICS HANDLE CONDITION NOTFND END-EXEC. The condition then abends the task again if raised.
  • HANDLE CONDITION does not survive an XCTL to another program in the way you might expect - the new program should set its own handling.

Example: handling map and file conditions

  • The example below sets up handling once, then issues several commands without RESP:
    PROCEDURE DIVISION. 0000-MAIN. EXEC CICS HANDLE CONDITION MAPFAIL(9000-MAP-ERROR) NOTFND(9100-NOT-FOUND) ERROR(9900-GENERAL-ERROR) END-EXEC. EXEC CICS RECEIVE MAP('CUSTMAP') MAPSET('CUSTSET') INTO(CUSTMAP-IN) END-EXEC. EXEC CICS READ FILE('CUSTFILE') INTO(CUST-RECORD) RIDFLD(CUST-ID) END-EXEC. PERFORM 2000-PROCESS-RECORD. EXEC CICS RETURN END-EXEC. 9000-MAP-ERROR. MOVE 'MAP NOT FOUND OR DATA ERROR' TO ERR-MSG. PERFORM 9500-DISPLAY-ERROR. 9100-NOT-FOUND. MOVE 'CUSTOMER RECORD NOT FOUND' TO ERR-MSG. PERFORM 9500-DISPLAY-ERROR. 9900-GENERAL-ERROR. MOVE EIBRESP TO WS-RESP. PERFORM 9500-DISPLAY-ERROR.

When to prefer HANDLE CONDITION

  • Use it when a whole paragraph issues many commands that can raise the same condition, so you avoid repeating RESP everywhere.
  • Keep the handler paragraphs close to the code they protect, and make each handler end with a RETURN or a branch back - never fall through into the next handler.
  • Do not overuse the ERROR catch-all. It hides which condition really happened; log EIBRESP there so the cause is recorded.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant