Loading

Easytrieve File matching : Synchronized Files

File1

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
A1
B1
D1

File2

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
XXX A1 YYYY ZZZZ
CCC A1 DDDDDDDDD
DDD A2 UUUUUUUUU
RRR B1 TTTTTTTTT
XXX B1 YYYY ZZZZ
CCC C1 DDDDDDDDD
DDD C2 UUUUUUUUU
RRR D1 TTTTTTTTT

Output File Should have only the records from file2, with second column values which are present in File1.
File1 has unique records
File2 should be in sorted order (Second column)
Ie,
OUTFILE

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
XXX A1 YYYY ZZZZ
CCC A1 DDDDDDDDD
RRR B1 TTTTTTTTT
XXX B1 YYYY ZZZZ
RRR D1 TTTTTTTTT

This Can be achieved in two ways. The first way is,

----+----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 5 2 A
 FILE OUTFILE
     OUT-REC 1 50 A
 JOB INPUT NULL
 GET FILE1
 GET FILE2
 DO WHILE NOT EOF FILE1 AND NOT EOF FILE2
   DO WHILE F2-KEY LE F1-KEY
      IF F1-KEY EQ F2-KEY
         PUT OUTFILE FROM FILE2
      END-IF
      GET FILE2
      IF EOF FILE2
         STOP
      END-IF
   END-DO
   GET FILE1
 END-DO
 STOP.

and the second way is,
Using JOB INPUT (FILENAME KEY(KEYNAME) FILENAME KEY(KEYNAME))

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

Matching the files in another way

----+----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           5     2   A
 FILE OUTFILE
 OUT-REC     1  50 A
 JOB INPUT (FILE1 KEY(F1-KEY)  FILE2 KEY(F2-KEY))
 IF FILE1
   IF FILE2
     PUT OUTFILE FROM FILE2
  END-IF
 END-IF
 GO TO JOB

Matching Multiple keys
(FILENAME KEY(KEY1,KEY2) FILENAME KEY(KEY1,KEY2))

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

Related Posts




blog comments powered by Disqus

There's 13 Comments So Far

Share your thoughts, leave a comment!