December 2005 Technical Tip - Easytrieve Plus: Matching files

Easytrieve Plus provides a simple technique for processing two file simultaneously and determining if records do or do not match based on a key field. Both files should be sorted by the key field (which they should have in common), then the Eastrieve Plus keyword MATCHED can be used to tell you if a key is found in one or both files. The complete JCL with test data and Easytrieve Plus source code is as follows:

//* JOBCARD HERE
//*******************************************************
//*  DEMO USE OF "KEY" AND "MATCHED" WITHIN EASYTRIEVE  *
//*******************************************************
//STEP010 EXEC PGM=EZTPA00
//FILEA    DD *
AAA N 111    Both  
AAA O 222    A only
BBB P 111    A only
BBB Q 222    Both  
CCC R 111    A only
CCC S 333    Both  
//FILEB    DD *
AAA T 111    Both  
AAA U 333    B only
BBB V 222    Both  
BBB W 333    B only
CCC X 222    B only
CCC Y 333    Both  
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
FILE FILEA
  A-RECORD    1   9   A
  A-KEY1      1   3   A
  A-MISC      5   1   A
  A-KEY2      7   3   A

FILE FILEB
  B-RECORD    1   9   A
  B-KEY1      1   3   A
  B-MISC      5   1   A
  B-KEY2      7   3   A

* WORKING-STORAGE
  W-A-RECORD  W  12   A
  W-B-RECORD  W  12   A
  W-MESSAGE   W  15   A

JOB INPUT ( FILEA KEY(A-KEY1 A-KEY2)   +
            FILEB KEY(B-KEY1 B-KEY2) )
  IF MATCHED FILEA FILEB 
     W-A-RECORD = A-RECORD
     W-B-RECORD = B-RECORD
     W-MESSAGE  = '*** MATCHED'
  ELSE-IF FILEA
     W-A-RECORD = A-RECORD
     W-B-RECORD = ' '
     W-MESSAGE  = '*** FILEA ONLY'
  ELSE
     W-A-RECORD = ' '
     W-B-RECORD = B-RECORD
     W-MESSAGE  = '*** FILEB ONLY'
  END-IF
  DISPLAY W-A-RECORD W-B-RECORD W-MESSAGE
Download file here.

The results of our Easytrieve Plus program are as follows:

AAA N 111    AAA T 111    *** MATCHED
AAA O 222                 *** FILEA ONLY 
             AAA U 333    *** FILEB ONLY 
BBB P 111                 *** FILEA ONLY 
BBB Q 222    BBB V 222    *** MATCHED 
             BBB W 333    *** FILEB ONLY 
CCC R 111                 *** FILEA ONLY 
             CCC X 222    *** FILEB ONLY 
CCC S 333    CCC Y 333    *** MATCHED

Want to know more about Easytrieve Plus? Give us a call! You can always count on Caliber Data Training for top quality IT training.


Go to the articles index. Written by Bill Qualls. Copyright © 2005 by Caliber Data Training 800.938.1222