READ and WRITE statements in Easytrieve

WRITE statement is used to write the record into an output file.
WRITE statement can be used to write record to any kind of file.
It is similar to PUT statement.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE INFILE FB(80 200)
   IN-REC 1 80 A
 FILE OUTFILE FB(80 200)
   OUT-REC 1 80 A
*
 WS-COUNT W 4 N VALUE 0
*
 JOB INPUT NULL
 GET INFILE
 DO WHILE NOT EOF INFILE
   MOVE IN-REC TO OUT-REC
   WRITE OUTFILE 
   IF OUTFILE:FILE-STATUS NE 0
       DISPLAY 'ERROR IN WRITING'
   END-IF
   WS-COUNT = WS-COUNT + 1
   GET INFILE
 END-DO
 DISPLAY WS-COUNT ' RECORDS WRITTEN'
 STOP 

READ statement is used only to read a VSAM file using a KEY.
For Non-VSAM files, use GET statement.

Update a record in VSAM file, using WRITE UPDATE.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
LIST ON
FILE MYVSAM VS(UPDATE)
MY-RECORD 1 80 A
MY-KEY 1 8 A
MY-VAL 9 5 A
JOB INPUT NULL
READ MYVSAM KEY 'A1234567' STATUS
IF MYVSAM:FILE-STATUS NE 0
DISPLAY 'UNSUCCESSFUL READ'
ELSE
DISPLAY HEX MYVSAM
MOVE 'ABCDE' TO MY-VAL
WRITE MYVSAM UPDATE
IF MYVSAM:FILE-STATUS NE 0
DISPLAY 'UNSUCCESSFUL UPDATE'
END-IF
END-IF
STOP

One thought on “READ and WRITE statements in Easytrieve”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.