Loading

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

Related Posts




blog comments powered by Disqus

There's 1 Comment So Far

Who Linked To This Post?

  1. GET and PUT statements in Easytrieve

Share your thoughts, leave a comment!