Module 6: CICS File Handling
READ
The READ command retrieves one record from a VSAM file. You identify the record in the RIDFLD option, and CICS places the record into the INTO area. It is used most often with key-sequenced files, but it also works with relative record and entry-sequenced files.
Syntax of the READ command
- FILE - the name of the file that contains the record. This name must be defined in the FCT.
- INTO - the data area that will hold the record after it is read.
- RIDFLD - the field that contains the key, relative record number, or relative byte address of the record to read.
- RRN - the RIDFLD value is a relative record number for an RRDS.
- RBA - the RIDFLD value is a relative byte address for an ESDS or KSDS.
- UPDATE - you intend to update the record. CICS holds the record for your task until you issue REWRITE, DELETE or UNLOCK, or the task ends.
A READ command that reads a record for update
- The most common use of READ is to fetch a record that the program is about to change. The UPDATE option locks the record for your task.
- If the record does not exist, the NOTFND exceptional condition occurs.
- Always code the RESP option and test the response code with DFHRESP so a missing record does not abend the task.
- Example:-
EXEC CICS READ FILE('CUSTMAS') INTO(CUSTOMER-MASTER-RECORD) RIDFLD(CM-CUSTOMER-NUMBER) UPDATE RESP(RESPONSE-CODE) END-EXEC. IF RESPONSE-CODE = DFHRESP(NOTFND) MOVE 'Customer not found.' TO MESSAGEO ELSE IF RESPONSE-CODE NOT = DFHRESP(NORMAL) PERFORM 9999-TERMINATE-PROGRAM END-IF.
