Loading

Using Files as Lookup tables in Easytrieve

Let us say, I have a lookup table file for Name of the Months. (DD name LOOKUP1 in our example program)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
01 JANUARY
02 FEBRUARY
03 MARCH
04 APRIL
05 MAY
06 JUNE
07 JULY
08 AUGUST
09 SEPTEMBER
10 OCTOBER
11 NOVEMBER
12 DECEMBER

and I have another file (DD name ACTUAL) for which the month names have to be read from the above file.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
05
12
33
03

Output File should have the month numbers from the ACTUAL file and should have fetched the month name from LOOKUP1 file and put in the output file.

Ie,

OUTFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
05 MAY
12 DECEMBER
33 INVALID MON
03 MARCH

This Can be achieved by the following program which uses the LOOKUP1 file as a table.

The field names ARG and DESC should not be changed (because those are keywords).

And also the TABLE file should not have high level group variable for the full record.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE LOOKUP1 TABLE
      ARG              1    2    A
      DESC             4   15    A
 FILE ACTUAL
      ACTUAL-REC        1    80   A
        MONTH-LIST      1     2   A
 FILE OUTFILE
      OUT-REC          1   80  A
      OUT-MONTH-NUM    1    2  A
      OUT-MONTH-NAME   4   15  A
 JOB INPUT NULL
 GET ACTUAL
     DO WHILE NOT EOF ACTUAL
        MOVE MONTH-LIST TO OUT-MONTH-NUM
        SEARCH LOOKUP1 WITH MONTH-LIST , GIVING OUT-MONTH-NAME
        IF NOT LOOKUP1
           MOVE 'INVALID MON' TO OUT-MONTH-NAME
        END-IF
        PUT OUTFILE
        GET ACTUAL
     END-DO
 STOP.

Related Posts




blog comments powered by Disqus

There's 7 Comments So Far

  •   Rajeev Nambyar
    May 12th, 2010 at 5:39 am

    very very helpful..

    Rajeev Nambyar
    MPhasis an HP company.. :)

  •   Anonymous
    May 26th, 2010 at 2:10 pm

    Hi,

    If I have a file of few month numbers only say 01 05 10 and requirement is if month number from input file match any entry in month number file append Yes in the output record else append No in the output record.
    How this can be achieved.

  •   Anonymous
    June 4th, 2010 at 1:31 pm

    Very crazy man!!!

  •   Karthik
    July 17th, 2010 at 3:45 pm

    Thanks Rajeev!

  •   Robert
    March 9th, 2012 at 1:37 pm

    What is the limit on the Table Size to be searched. I am getting : A008 TOO MANY TABLE ENTRIES – DATETBL

  •   Karthik
    March 15th, 2012 at 6:02 am

    Hi Robert,
    Can you try specifying your table size in the FILE TABLE declaration?
    say, if you have 1500 records in your FILE, declare as FILE LOOKUP1 TABLE(1500)

    Thanks,
    Karthik.

    A008 TOO MANY TABLE ENTRIES – filename

    There are more table entries in the indicated external table file than
    specified on the related FILE statement. Recompile the program after
    increasing the value in the file’s TABLE parameter.

  •   Satheesh
    May 14th, 2012 at 7:21 am

    A008 TOO MANY TABLE ENTRIES – filename

    This error is coming because,you can’t have more than 3,55,000 records in Lookup table

Share your thoughts, leave a comment!