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

  •   kiranmayi
    March 27th, 2012 at 8:08 am

    list on ?? could you please tell why list on is used??

  •   Karthik
    March 28th, 2012 at 3:44 am

    Hi Kiran,
    LIST ON specifies that all subsequent program statements are to be printed in SYSPRINT (this is the default option).
    LIST OFF suppresses the printing of statements.

  •   kiranmayi
    March 28th, 2012 at 2:09 pm

    thanks for your response.

    the above code is not working i.e

    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

    After sub the job the return code is zero, but ‘records written’ is not displayed. I guess display to be return before go to job statement.

  •   Karthik
    March 29th, 2012 at 1:29 am

    Hi Kiranmayi,

    The DISPLAY statement in your program will never execute. Once the End of INFILE is reached, the program terminates. If you give the DISPLAY statement before the GOTO JOB statement, it will be displayed for every record written to output file.
    You can try any of the below ways to get the record count after writing the records to output file.

    ——————————————————————–
    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 EOF INFILE
    PUT OUTFILE FROM INFILE
    WS-COUNT = WS-COUNT + 1
    GET INFILE
    END-DO
    DISPLAY ‘ RECORDS WRITTEN : ‘ WS-COUNT
    STOP
    ——————————————————————–
    or

    ——————————————————————–
    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 START BEGIN-PROC FINISH FINAL-PROC
    PUT OUTFILE FROM INFILE
    WS-COUNT = WS-COUNT + 1
    GOTO JOB
    *
    BEGIN-PROC. PROC
    DISPLAY ‘ STARTING ..’
    END-PROC
    *
    FINAL-PROC. PROC
    DISPLAY ‘ RECORDS WRITTEN : ‘ WS-COUNT
    END-PROC
    *
    ——————————————————————–
    Hope that helps!

  •   kiranmayi
    March 29th, 2012 at 4:26 am

    thanks karthik.. its working.. :)

  •   Karthik
    March 29th, 2012 at 5:27 am

    Kiranmayi, great! thanks for reading my blog!

  •   kiranmayi
    March 29th, 2012 at 1:26 pm

    Im very much thankful to you karthik..

    Im a beginner in easytrieve and i started my journey with our blog.. it is helping me a lot :)

  •   TRIPTI
    June 27th, 2012 at 12:12 pm

    I have a JOB INPUT statement and then the file processing statements.

    If I do NOT specify GO TO JOB at the end, will not the next record in the file be read by default?

    example:

    JOB INPUT AAAAAI
    BBBBBO-RECORD = AAAAAI-RECORD
    PUT BBBBBO

    Is it required to specify GO TO JOB here to put all the records in AAAAAI to BBBBBO file?

  •   Karthik
    June 28th, 2012 at 6:52 am

    Hi Tripti,

    yes, you need to specify GO TO JOB at the end, so that all the records in the Input file are processed.

  •   TRIPTI
    June 29th, 2012 at 7:33 am

    I thought job statement will read next record from the driver file even if GO TO JOB is not specified! Are you sure this is wrong?

  •   Karthik
    June 29th, 2012 at 11:12 am

    Tripti, you are right. GO TO JOB is not mandatory for reading next record.
    All the below formats of JOB statements process all the records from Input file INFILE.
    ——————————
    *
    FILE INFILE
    INREC 1 4 A
    JOB INPUT INFILE
    DISPLAY INREC
    *
    ——————————
    *
    FILE INFILE
    INREC 1 4 A
    JOB INPUT INFILE
    DISPLAY INREC
    END
    *
    ——————————
    *
    FILE INFILE
    INREC 1 4 A
    JOB INPUT INFILE
    DISPLAY INREC
    GO TO JOB
    *

  •   TRIPTI
    July 2nd, 2012 at 1:19 pm

    Thanks!

  •   Lalitha
    July 16th, 2012 at 6:17 am

    Please let me know how to execute a easytrive program thru jcl

  •   Karthik
    July 17th, 2012 at 3:03 am

    Lalitha,

    JCL step should look like,

    //STEP01 EXEC PGM=EZTPA00
    //FILEA DD DSN=FILEA,DISP=SHR
    //FILEB DD DSN=FILEB,DISP=SHR
    //FILEC DD DSN=FILEC.DIF,
    // DISP=(NEW,CATLG,DELETE),
    // SPACE=(CYL,(100,50),RLSE),
    // DCB=(RECFM=FB,LRECL=5200,BLKSIZE=0)
    //SYSOUT DD SYSOUT=*
    //SYSPRINT DD SYSOUT=*
    //SYSIN DD *
    EASYTRIEVE CODE HERE
    /*

  •   Priyanka
    July 17th, 2012 at 10:13 am

    Hi,
    I am a beginner to EASYTRIEVE.
    I tried a matching logic but its not working.Can you help:
    JOB INPUT (FILEB KEY(IN-POLNUM2) FILEA KEY(IN-POLNUM))

    IF MATCHED FILEB FILEA
    OUT-MPRFLD1A = IN-MPRFLD1A
    OUT-MPRFIXED = 0021
    OUT-MPRFLD1-LONG = IN-MPRFLD1-LONG
    PUT FILEC
    ELSE
    OUT-POLNUM = IN-POLNUM2
    PUT FILED
    END-IF.
    GOTO JOB.

    I am getting return code 16.

  •   Karthik
    July 17th, 2012 at 12:49 pm

    Hi Priyanka,

    In the ELSE part (writing FILED), you want the records from FILEB, which do not have matching records in FILEA. Is that correct?

    if so, please change the ELSE part as,
    ELSE
    IF FILEB <—- add this OUT-POLNUM = IN-POLNUM2 PUT FILED END-IF <—- and this END-IF You need to ensure that the non matching record was coming from FILEB.

  •   Velu
    June 17th, 2013 at 10:10 am

    Hi Karthik…

    I’m new to easytrieve. Actaully i’m trying to compare a field from two input files. I mean 1st input file(File-A) is from the control card and another one is a PS file(File-B). From the control card i have to take 9 digit as a key and compare with File-B’s first field.

    When I tried I’m getting the below error.
    IEA995I SYMPTOM DUMP OUTPUT 699
    SYSTEM COMPLETION CODE=013 REASON CODE=00000034

    Could you pls help me on this??

    File-A length is:80(Key start pos:10 to 9)
    File-B length is:614(Key start pos: 1 to 9)

    If matched
    Put output from File-B
    esle
    go to job
    end-if.

    My Code is:
    LIST ON
    FILE INPUT1
    LISTE 10 9 N
    FILE INPUT2
    LILI 1 9 N
    REM-INPUT 10 605 A
    FILE OUTPUT
    OUT-REC 1 614 A
    *
    CNT-INPUT S 6 N MASK ‘ZZZ,ZZ9’
    CNT-OUT1 S 6 N MASK ‘ZZZ,ZZ9’
    *=============================================================
    * START OF MAINLINE PROGRAM:
    *=============================================================
    JOB INPUT(INPUT1 KEY(LISTE) INPUT2 KEY(LILI)) FINISH ENDPROC

    CNT-INPUT = CNT-INPUT + 1

    IF MATCHED
    CNT-OUT1 = CNT-OUT1 + 1
    DISPLAY ‘ OUTPUT : ‘ LILI
    PUT OUTPUT FROM INPUT2

    ELSE
    GO TO JOB
    END-IF
    *=============================================================
    * END OF MAINLINE PROGRAM: (A ‘GO TO JOB’ IS IMPLIED)
    *=============================================================
    *
    ENDPROC. PROC
    DISPLAY SKIP 2 ‘Total Input : ‘ CNT-INPUT
    DISPLAY SKIP 2 ‘Total Output : ‘ CNT-OUT1
    END-PROC

Share your thoughts, leave a comment!