Module 11: CICS Error Handling and Debugging
RESP
RESP is an option you code on an EXEC CICS command. It tells CICS: do not abend the task if something goes wrong - put a numeric response code in my variable instead. The program then tests the code and decides what to do next. It is the most widely used error-handling technique in CICS.
What is the RESP option
- RESP is coded on the command itself, for example on READ, WRITE, SEND MAP, or RECEIVE MAP.
- CICS stores a response code in the variable you name. Zero (NORMAL) means the command worked.
- The variable must be defined as PIC S9(8) COMP (a fullword binary field).
- When RESP is coded, the condition does not trigger any active HANDLE CONDITION for that command. The program takes full responsibility for checking the value.
- If you forget to test RESP, the program continues as if nothing went wrong - so always test it right after the command.
Testing the response code with DFHRESP
- CICS supplies a copybook of condition names. In COBOL you compare your RESP variable with DFHRESP(condition), for example DFHRESP(NOTFND) or DFHRESP(NORMAL).
- The copybook is included with: COPY DFHRESP in WORKING-STORAGE. It defines every condition name as its numeric value.
- An EVALUATE on the RESP variable with WHEN DFHRESP(...) branches is the standard, readable pattern.
- Always include a WHEN OTHER branch for unexpected codes, so no error slips through silently.
Example: RESP on a file read
- WORKING-STORAGE needs the response field and the DFHRESP copybook, then the read is coded with RESP:WORKING-STORAGE SECTION. 01 WS-RESP PIC S9(8) COMP. COPY DFHRESP. PROCEDURE DIVISION. EXEC CICS READ FILE('CUSTFILE') INTO(CUST-RECORD) RIDFLD(CUST-ID) RESP(WS-RESP) END-EXEC. IF WS-RESP = DFHRESP(NORMAL) PERFORM 2000-PROCESS-RECORD ELSE IF WS-RESP = DFHRESP(NOTFND) MOVE 'CUSTOMER NOT FOUND' TO ERR-MSG ELSE MOVE 'FILE READ FAILED' TO ERR-MSG END-IF PERFORM 9000-DISPLAY-ERROR END-IF.
RESP behaviour to remember
- RESP is per command. Each EXEC CICS command that can fail needs its own RESP if you want local handling.
- RESP and HANDLE CONDITION do not mix on the same command: when RESP is coded, HANDLE CONDITION is bypassed for that command.
- CICS also fills EIBRESP after every command, so even without RESP you can check EIBRESP - but coding RESP makes the intent explicit.
- For file and TD/TS commands you can pair RESP with NOSUSPEND so the task never waits on a lock; the lock conflict comes back as a response code instead.
