Using CICS RESP and RESP2 to Diagnose a VSAM READ Without Hiding a Real Failure
A CICS transaction that says “record not found” may be handling an expected business condition—or it may be reducing an allocation, security, or data-definition problem to an unhelpful screen message. This tutorial shows how to capture `RESP` and `RESP2` around a keyed VSAM `READ`, separate an expected absence from a technical failure, and preserve evidence before a recovery decision.
A CICS transaction that says “record not found” may be handling an expected business condition—or it may be reducing an allocation, security, or data-definition problem to an unhelpful screen message. This tutorial shows how to capture RESP and RESP2 around a keyed VSAM READ, separate an expected absence from a technical failure, and preserve evidence before a recovery decision.
The example is fictional and uses generic resource names. CICS definitions, response values, error conventions, and security rules vary by installation; test a change in an approved environment and do not retry an online transaction simply because a key lookup failed.
Goal: make the lookup outcome explicit
Consider a customer-service transaction that reads a KSDS record by account number. A missing account is normally a valid outcome: the clerk may have entered a new number, or the account may not be active. A program failure, however, deserves a different message and a support trail.
A weak design treats every nonzero result as “not found.” That can conceal a disabled file, an unavailable resource, an incorrect key length, or a permission issue. The immediate screen appears friendly, but the support team loses the clue that distinguishes a data question from a platform or definition problem.
The working objective is not to display raw CICS codes to an end user. It is to retain the response detail for diagnostics and translate it into one of three controlled application outcomes:
| Lookup outcome | User-facing action | Support implication |
|---|---|---|
| Record is absent under the agreed key | Explain that no eligible account was found | Normal business path; log only if local policy requires it |
| Record is read successfully | Continue with validation and display | No lookup incident |
| Any other CICS response | Stop the transaction safely and issue a reference | Investigate resource, definition, security, or coding evidence |
This distinction matters particularly when a prior screen or a batch update has left the user expecting a record to exist. An expected NOTFND response does not prove that the account was never created; it only says this READ did not locate a record under the supplied key and resource at that moment.
A small COBOL pattern for a keyed READ
The following pattern uses RESP and RESP2 on the command rather than allowing a generic error path to guess what happened. The constants shown here are illustrative names; use the condition values and copybooks approved at your site.
01 WS-ACCOUNT-KEY PIC X(10).
01 WS-CUST-RECORD PIC X(180).
01 WS-CICS-RESP PIC S9(8) COMP.
01 WS-CICS-RESP2 PIC S9(8) COMP.
01 WS-LOOKUP-RESULT PIC X(12).
88 ACCOUNT-FOUND VALUE 'FOUND'.
88 ACCOUNT-MISSING VALUE 'NOT-FOUND'.
88 ACCOUNT-READ-ERROR VALUE 'READ-ERROR'.
MOVE LOW-VALUES TO WS-CUST-RECORD
MOVE 'READ-ERROR' TO WS-LOOKUP-RESULT
EXEC CICS READ
DATASET('CUSTKSDS')
INTO(WS-CUST-RECORD)
RIDFLD(WS-ACCOUNT-KEY)
RESP(WS-CICS-RESP)
RESP2(WS-CICS-RESP2)
END-EXEC
EVALUATE WS-CICS-RESP
WHEN DFHRESP(NORMAL)
MOVE 'FOUND' TO WS-LOOKUP-RESULT
WHEN DFHRESP(NOTFND)
MOVE 'NOT-FOUND' TO WS-LOOKUP-RESULT
WHEN OTHER
MOVE 'READ-ERROR' TO WS-LOOKUP-RESULT
PERFORM WRITE-CICS-DIAGNOSTIC
END-EVALUATE.
```
On a successful read, later logic can validate the account status, effective date, or authorization. On NOTFND, the map can ask the clerk to recheck the key or offer the approved new-account path. On any other response, the transaction should avoid using the cleared record area and should not continue as though a lookup occurred.
RESP2 is valuable because the main response condition can be broad while the secondary response supplies further detail for diagnosis. Store or log it with the primary response, but do not build production decisions around a guessed numeric RESP2 value. Consult the CICS Transaction Server documentation for the exact command and release in use, then translate only documented, locally tested cases into application behavior.
Why response handling and condition handling need one owner
CICS offers more than one way to direct command error processing, including RESP/RESP2, HANDLE CONDITION, and NOHANDLE. A program can become difficult to reason about when it mixes these mechanisms without a clear convention. For example, a persistent HANDLE CONDITION NOTFND can branch away from the paragraph that a maintainer expects to evaluate WS-CICS-RESP.
For a small, local operation such as this lookup, explicit RESP/RESP2 with an immediate EVALUATE keeps the decision beside the command. That makes code review easier: a reviewer can see which outcomes are intentional and whether the record is safe to use. A transaction framework may instead centralize handling. Either approach can work when ownership is documented; do not add a second mechanism to “be safe” without understanding its precedence and scope.
Evidence to capture when the result is not expected
A support investigation is stronger when it starts with the exact transaction event rather than a report that “CICS could not find the account.” Capture only data permitted by local security and privacy rules. Mask the business key in shared tickets if it is sensitive.
Transaction ID and terminal/user context (per local policy)
Time of the failing command and CICS region identifier
Program name, program version or promotion reference
Resource name used by the command: CUSTKSDS
Operation: READ with the key length/format, not the full sensitive key
RESP and RESP2 values, plus the application diagnostic reference
Whether the same key succeeds in an approved test path
Recent file/resource status messages and relevant CICS monitoring evidence
This list supports several separate checks. Is the program using the intended file definition? Is the key in the expected character or binary representation and length? Did a deployment alter a copybook or redefine the field? Is the resource available to this transaction and region? A user’s statement that the account exists in another application is useful context, but it is not proof that this program is reading the same KSDS, key, or record version.
Diagnosis path: start with the business outcome, then the command
Use this sequence before changing code or asking operations to alter a resource:
Unexpected lookup result
|
+-- Was the displayed account key accepted by input validation?
| +-- no: correct the input path; do not investigate VSAM first
|
+-- Is RESP = NOTFND?
| +-- yes: verify key format, target resource, and business eligibility
| +-- no: retain RESP/RESP2 and inspect resource/security/definition evidence
|
+-- Did the program use the record area after a failed READ?
+-- yes: treat that as a code defect and assess any unsafe follow-on action
A key-format problem is common enough to deserve explicit attention. A ten-byte character account key with leading zeroes is not interchangeable with a display-numeric field after an implicit conversion. Likewise, an alternate index design may require a different READ pattern from the prime-key access shown here. Verify the file layout and command contract rather than changing field positions from memory.
Support checklist before retrying or changing a definition
- Confirm the transaction, CICS region, program version, resource name, and time of the actual failure.
- Preserve
RESP,RESP2, and the application diagnostic reference; do not replace them with a generic “not found” message in the evidence. - Check that the key length, format, leading-zero rule, and selected resource match the active copybook and file design.
- Establish whether
NOTFNDis a permitted business result for this transaction state or an unexpected outcome requiring application-owner review. - For another response, inspect approved CICS, security, and resource-status evidence before proposing a code or definition change.
- Check whether any downstream action was attempted after the failed read, especially updates, temporary-storage writes, or external requests.
- Do not enable, redefine, close/open, or retry a production resource without the responsible operations and application recovery process.
Practical takeaway
A VSAM READ is not simply successful or missing. Treat NORMAL, the expected absence case, and every other CICS response as separate outcomes. Capturing RESP and RESP2 at the command, preserving focused evidence, and stopping unsafe follow-on logic gives users a clearer result and gives support a real diagnosis path.