The REWRITE command is used to update a record already read. Before issuing a REWRITE command, READ command must have been issued with the UPDATE option. The key field in the record cannot be changed.
Below is the syntax for REWRITE command.
EXEC CICS REWRITE FILE(name) FROM(data-area) LENGTH(data-value) END-EXEC.
Let us see the parameters used in the READ command.
Specifies the name of the file to be accessed.
Specifies the data-area from which the data is to be written.
specifies the length, as a halfword binary value, of the data area where the record is written from.
Let us see an example of CICS program for READ command.
IDENTIFICATION DIVISION. PROGRAM-ID. IBMMF. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-REC-LEN PIC S9(4) COMP. 01 WS-KEY-LEN PIC S9(4) COMP. 01 WS-REC-KEY PIC 9(6). 01 WS-REC-DATA PIC X(80). PROCEDURE DIVISION. MOVE +80 TO WS-REC-LEN. MOVE ‘502258’ TO WS-REC-KEY. MOVE 6 TO WS-KEY-LEN. EXEC CICS READ FILE('STDLST') INTO(WS-REC-DATA) LENGTH(WS-REC-LEN) RIDFLD(WS-REC-KEY) KEYLENGTH(WS-KEY-LEN) UPDATE END-EXEC. MOVE '502258IBMMAINFRAMER TUTORIALS' TO WS-STD-REC. EXEC CICS REWRITE FILE('STDLST') FROM(WS-REC-DATA) LENGTH(WS-REC-LEN) END-EXEC.
This example shows how to write a record in 'STDLST' file where Student-id is the primary key. A new record with 502258 student id will be written in the 'STDLST' file.
|DISABLED||A file is disabled|
|NOTOPEN||File is not open.|
|NOTAUTH||A resource security check has failed on FILE(filename).(i.e. User does not have enough permissions to access the file).|
|NOSPACE||No space is available for new record.|
|LENGERR||Mismatch between the length specified in command and actual length of the record.|
|INVREQ||Rewrite command executed without prior READ command with UPDATE option.|
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!