Module 6: CICS File Handling
WRITE
The WRITE command adds a new record to a VSAM key-sequenced, entry-sequenced or relative record file. The record comes from the FROM area, and the RIDFLD option tells CICS where the new record belongs.
Syntax of the WRITE command
- FILE - the name of the file where the record will be written. This name must be defined in the FCT.
- FROM - the data area that contains the record to be written.
- RIDFLD - the field that contains the key, relative record number, or relative byte address of the record to write.
- RRN - the file is a relative record file, and the RIDFLD value is a relative record number.
- RBA - the file is an entry-sequenced file. When the command completes, the RIDFLD field is set to the RBA of the new record.
A WRITE command that writes a record to a key-sequenced file
- For a KSDS, the key in the RIDFLD field must be unique. If a record with that key already exists, the DUPREC exceptional condition occurs.
- For an ESDS, the record is appended at the end of the file and CICS returns the new record's RBA in the RIDFLD field.
- For an RRDS, the record goes into the slot numbered by the RRN, which must be empty.
- Example:-
EXEC CICS WRITE FILE('CUSTMAS') FROM(CUSTOMER-MASTER-RECORD) RIDFLD(CM-CUSTOMER-NUMBER) RESP(RESPONSE-CODE) END-EXEC. IF RESPONSE-CODE = DFHRESP(DUPREC) MOVE 'Customer already exists.' TO MESSAGEO ELSE IF RESPONSE-CODE NOT = DFHRESP(NORMAL) PERFORM 9999-TERMINATE-PROGRAM END-IF.
