Loading

GET and PUT statements in Easytrieve

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 

Related Posts




blog comments powered by Disqus

There's 9 Comments So Far

  •   Rekha
    May 15th, 2012 at 9:53 am

    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.

  •   Karthik
    May 15th, 2012 at 10:47 am

    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

  •   Rekha
    May 17th, 2012 at 9:16 am

    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

  •   Karthik
    May 17th, 2012 at 10:34 am

    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.

  •   Rekha
    May 18th, 2012 at 6:40 am

    Hi Karthik,

    Its working…!!! :) Thank you so much….

  •   Bhaskar
    March 2nd, 2013 at 3:28 pm

    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.

  •   Karthik
    March 3rd, 2013 at 1:20 pm

    Hi Bhaskar,

    You cannot re-write the file like that.
    Are you using VSAM? If yes, read http://code.xmlgadgets.com/2011/10/01/update-re-write-vsam-file-in-easytrieve/

  •   Bruce Lehman
    May 16th, 2013 at 8:41 pm

    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?

Who Linked To This Post?

  1. READ and WRITE statements in Easytrieve

Share your thoughts, leave a comment!