Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 6: CICS File Handling


REWRITE

The REWRITE command updates a record in a file. Unlike WRITE, which adds a new record, REWRITE replaces the contents of a record that is already there. It is the second half of the classic read-for-update pattern.

Syntax of the REWRITE command

  • FILE - the name of the file that contains the record to be updated. This name must be defined in the File Control Table (FCT).
  • FROM - the data area that contains the updated record to be written back.
  • REWRITE has no RIDFLD option. CICS already knows which record to update because you read it with the UPDATE option first.

The read-for-update pattern

  • Before you issue REWRITE, you must issue a READ command with the UPDATE option for the same record. The UPDATE read holds the record for your task.
  • Change the fields you need in the record area, then issue REWRITE with the FROM option pointing at the same area.
  • You cannot change the value of the primary key with REWRITE. If you try, the INVREQ exceptional condition occurs. To change a key, delete the old record and write a new one.
  • Example:-
    EXEC CICS READ FILE('CUSTMAS') INTO(CUSTOMER-MASTER-RECORD) RIDFLD(CM-CUSTOMER-NUMBER) UPDATE RESP(RESPONSE-CODE) END-EXEC. IF RESPONSE-CODE = DFHRESP(NORMAL) ADD 1 TO CM-ORDER-COUNT EXEC CICS REWRITE FILE('CUSTMAS') FROM(CUSTOMER-MASTER-RECORD) RESP(RESPONSE-CODE) END-EXEC IF RESPONSE-CODE NOT = DFHRESP(NORMAL) PERFORM 9999-TERMINATE-PROGRAM END-IF END-IF.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant