CICS - WRITE



Write command is used to add new records to a file. The parameters used in Write command are same as we had described before. Data is picked from the data area mentioned in the FROM clause. Following is the syntax for Write command −

Syntax

EXEC CICS WRITE
   FILE(name)
   FROM(data-area)
   RIDFLD(data-area)
   LENGTH(data-value)
   KEYLENGTH(data-value)
END-EXEC.

Example

Following is the example to write a record in 'FL001' file where Student-id is the primary key and a new record with 101 student id will be written in the file −

IDENTIFICATION DIVISION.                                         
PROGRAM-ID. HELLO.                                               
DATA DIVISION. 
WORKING-STORAGE SECTION.
01 WS-STD-REC-LEN    PIC S9(4) COMP.
01 WS-STD-KEY-LEN    PIC S9(4) COMP.
01 WS-STD-REC-KEY    PIC 9(3).
01 WS-STD-REC        PIC X(70).
PROCEDURE DIVISION.
MOVE +70           TO WS-STD-REC-LEN.
MOVE ‘101’         TO WS-STD-REC-KEY.
MOVE 3             TO WS-STD-KEY-LEN.
MOVE '101Mohtahim M TutorialsPoint' TO WS-STD-REC.
EXEC CICS WRITE
   FILE ('FL001')
   FROM (WS-STD-REC)
   LENGTH (WS-STD-REC-LEN)
   RIDFLD (WS-STD-REC-KEY)
   KEYLENGTH (WS-STD-KEY-LEN)
END-EXEC.

Write Command Exceptions

The following table shows the list of exceptions that arise during a WRITE statement −

Sr.No Exception & Description
1

NOTOPEN

File is not open.

2

FILENOTFOUND

File entry is not made in FCT.

3

LENGERR

Mismatch between the length specified in command and actual length of the record.

4

NOTAUTH

If the user does not have enough permissions to use the file.

5

DUPKEY

If more than 1 record satisfy the condition on the alternate key.

6

NOSPACE

There is not enough space in the dataset.

cics_file_handling.htm
Advertisements