TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

CICS REWRITE Command


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.

Syntax:

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.

  • FILE(filename)

    Specifies the name of the file to be accessed.

  • FROM(data-area)

    Specifies the data-area from which the data is to be written.

  • LENGTH

    specifies the length, as a halfword binary value, of the data area where the record is written from.


Example:

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.

Description:

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.


REWRITE Command Exception conditions:


ExceptionDescription
DISABLEDA file is disabled
NOTOPENFile is not open.
NOTAUTHA resource security check has failed on FILE(filename).(i.e. User does not have enough permissions to access the file).
NOSPACENo space is available for new record.
LENGERRMismatch between the length specified in command and actual length of the record.
INVREQRewrite 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!

Are you looking for Job Change? Job Portal