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 

9 thoughts on “GET and PUT statements in Easytrieve”

  1. 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.

  2. 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

  3. 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

  4. 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.

  5. 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.

  6. 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?

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.