Loading

JOB Input statement in Easytrieve

Job statement is the main section or Procedure division of the easytrieve.
Let us see the different types of JOB statements.
JOB INPUT NULL
If you want to process the files yourself and you dont want the Easytrieve to read/match files for you, please use JOB INPUT NULL.
e.g,

----+----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
   PUT OUTFILE FROM INFILE
   WS-COUNT = WS-COUNT + 1
   GET INFILE
 END-DO
 DISPLAY WS-COUNT ' RECORDS WRITTEN'
 STOP

JOB INPUT
In the above case, if you want the input file to be automatically read, record by record, use the below format
JOB INPUT

----+----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 INFILE
   PUT OUTFILE FROM INFILE
 GO TO JOB
 DISPLAY WS-COUNT ' RECORDS WRITTEN'
 STOP

In the above program, the JOB statement automatically reads a record from INFILE, each time it executes. But what the GO TO JOB is doing?
It is looping the program to read all the records from the INFILE until End of the file. Otherwise, the STOP statement will terminate the program after the first record itself. There is another smarter way to achieve this.

JOB INPUT … END

----+----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 INFILE
   PUT OUTFILE FROM INFILE
 END
 DISPLAY WS-COUNT ' RECORDS WRITTEN'
 STOP

The END statement makes the code to look better. It still reads all the records from INFILE and writes to OUTFILE.

File matching : Synchronized files

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE FILE1
          F1-REC           1    50   A
          F1-KEY           1     2   A
 FILE FILE2
          F2-REC           1    50   A
          F2-KEY           7     2   A
 FILE OUTFILE
 OUT-REC     1  50 A
 JOB INPUT (FILE1 KEY(F1-KEY)  FILE2 KEY(F2-KEY))
 IF MATCHED
     PUT OUTFILE FROM FILE2
 END-IF
 GO TO JOB

Related Posts




blog comments powered by Disqus

There's 17 Comments So Far

Share your thoughts, leave a comment!