GET and PUT statements are used to Read and Write to/from a file.
See a sample Easytrieve program below.
----+----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 PUT OUTFILE WS-COUNT = WS-COUNT + 1 GET INFILE END-DO DISPLAY WS-COUNT ' RECORDS WRITTEN' STOP
Also learn about READ and WRITE statements.
There is another simple way to do this, using PUT FROM
----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- ... JOB INPUT NULL GET INFILE DO WHILE NOT EOF INFILE PUT OUTFILE FROM INFILE WS-COUNT = WS-COUNT + 1 GET INFILE END-DO DISPLAY WS-COUNT ' RECORDS WRITTEN' STOP
Hi Karthik,
I’m writing data into a NON-VSAM file. When i give PUT OUTFILE the data is not getting written into the OUTFILE. When I give PUT OUTFILE FROM INFILE its working. I don’t know what is the difference between these two. Can you clarify me.
when ‘PUT OUTFILE’ statement is executed, the data present in OUT-REC will be written to the OUTFILE.
so, we need to first populate some data to OUT-REC, before doing PUT.
like,
FILE OUTFILE FB(80 200)
OUT-REC 1 80 A
JOB INPUT NULL
MOVE ‘MY OUTPUT STARTS’ TO OUT-REC
PUT OUTFILE
STOP
FILE OUTFILE FB(60 600)
OUT-REC W 60 A
FL-CNTL-KEY OUT-REC 22 A
FL-TFR-AFL-FLG OUT-REC +22 1 A
FL-LINK-SYS-ID OUT-REC +23 2 A
FL-LINKAGE-CNTL OUT-REC +25 35 A
*
JOB INPUT IMMSTRI ENVIRONMENT COBOL
MOVE WS-CNTL-KEY TO FL-CNTL-KEY
WS-TFR-AFL-CNT = WMS-TRNSFR-AFFL-TRLR
SUB = WS-TFR-AFL-CNT
MOVE WMS-TRNSFR-AFFL-FLAG(SUB) TO FL-TFR-AFL-FLG
MOVE WMS-LINK-SYS-ID(SUB) TO FL-LINK-SYS-ID
MOVE WMS-LINKAGE-CNTL(SUB) TO FL-LINKAGE-CNTL
PUT OUTFILE
GOTO JOB
This is the code i have written.
I have moved the values to the OUTFILE variables. Still it is not appearing in the OUTFILE. How can i modify the above code so that I will get the data in the OUTFILE
Rekha,
Please change
OUT-REC W 60 A
to
OUT-REC 1 60 A
-since it is not a working storage variable, but a file variable.
Hi Karthik,
Its working…!!! 🙂 Thank you so much….
How can i update/rewrite the flat file ? Below code is getting error. Can you please suggest in this.
FILE INFILE FB(80 200)
IN-REC 1 80 A
GET INFILE
IF INREC = 0
INREC = 1
ELSE
INREC = 2
END-IF
PUT INFILE.
Hi Bhaskar,
You cannot re-write the file like that.
Are you using VSAM? If yes, read https://littlecode.in/2011/10/01/update-re-write-vsam-file-in-easytrieve/
When accessing vsam files in Easytrieve is it possible to do the same thing that in Cobol would be accomplished with START and READ NEXT logic?