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

Share your thoughts, leave a comment!