Generic File Comparison Utility

The program can be run on any two files with identical file layouts. For the file, Key fields and Data fields are specified. The Key fields do not need to correspond with the file's "natural" key, but the combination of key fields must result in a unique key. At least one field of each type (Key and Data) must be specified. The program sorts the files based upon the specified key fields, and the performs a merge sort (aka Matching Records). One of four states is possible after each read:

  1. The first key is less than the second key (Unmatched records)
  2. The second key is less than the first key (Unmatched records)
  3. The keys are equal, but there are differences in the specified data fields (Unmatched records)
  4. The keys are equal and the specified data fields are different (Matched records)

The table that drives all this is CP1000F. Following is an example when loaded for JDEdwards UDC tables:

 AERECTYP   AEFLDTYP   AEFLDSEQ   AENAM      AEDSC                         
 ---------- ---------- ---------- ---------- ----------   
 UDC2       K                   1 DRSY       DRSY                          
 UDC2       K                   2 DRRT       DRRT                          
 UDC2       K                   3 DRKY       DRKY                          
 UDC2       D                   1 DRDL01     Description 1                 
 UDC2       D                   2 DRDL02     Description 2                 
 UDC2       D                   3 DRSPHD     Spec Hand                     
 UDC2       D                   4 DRHRDC     HardCod                   

The program is called from the command line with the following parameters:

The program call looks like this:

call cp1000c (UDC2 F0006 F0006 CLTCOM CLTCOMDEV 'Generic File Comparison - UDC Detail    ' '0')

The generated report looks like this:

 CP1000                                                Compare/Contrast Files                                                 1/26/05 
 Page:         1                                Generic File Comparison - UDC Detail                                         13:46:15 
 Left File:  F0005 CLTCOM                
 Right File: F0005 CLTCOMDEV             
   DRSY DRRT DRKY       Description 1                  Description 2                  Spec Hand  HardCod                               
   ==== ==== ========== ------------------------------ ------------------------------ ---------- -------                               
 R 82    GR  DJEKYLL    Personal WW Reports                                                         N                                 
 L 82    GR  FJUSTICE   Frank Justice                                                               N                                 
   83    08   CA1       CA1 - Long Beach District                                                   N                                 
                        CA1 - Coastal District                                                      N                                 

The image I had in mind while writing this was of someone sitting with two file dumps in front of her (comparing them line by line); one on the left (L) and one on the right (R). All we are doing is automating the comparison. The significance of the report is as follows (by line):

  1. Record 82/GR/DJEKYLL exists in CLTCOMDEV, but not CLTCOM
  2. Record 82/GR/FJUSTICE exists in CLTCOM, but not CLTCOMDEV
  3. Record 83/08/CA1 exists in both files, but with differing data

A couple of notes:

In addition:


The following link takes you to the source code, written in beautiful /free ILE/RPG. Both the source and the compiled objects are distributed under a create commons license.

cp1000r.txt - Table-driven Generic File Comparison


Right-click on the following link to download a save file (saved to V5R1) containing the Utility. Create an empty save file on the target machine, ftp the downloaded file up to the save file, and display the save file. You should see something similar to the following:

                       Display Saved Objects - Save File                       
                                                                               
Library saved  . . . :   CPANDOS               Release level  . . . :   V5R1M0 
ASP  . . . . . . . . :   1                     Data compressed  . . :   No     
Save file  . . . . . :   CP1000                Objects displayed  . :   4      
  Library  . . . . . :     CPANDOS             Objects saved  . . . :   4      
Records  . . . . . . :   1024                  Access paths . . . . :   0      
Save command . . . . :   SAVOBJ                                                
Save active  . . . . :   *NO                                                   
Save date/time . . . :   01/26/05   14:28:05                                   
                                                                               
Type options, press Enter.                                                     
  5=Display saved data base file members                                       
                                                                               
Opt  Object             Type     Attribute     Owner         Size (K)   Data   
     CP1000C            *PGM     CLP           CPANDO              60   YES    
     CP1000R            *PGM     RPGLE         CPANDO             380   YES    
     CP1000             *FILE    PF            CPANDO             344   YES
     CP1000F            *FILE    PF            CPANDO              52   YES    
                                                                               
                                                                               
                                                                               
                                                                               
F3=Exit        F12=Cancel                                                     

Execute the following command to restore:

RSTOBJ OBJ(*ALL) SAVLIB(CPANDOS) DEV(*SAVF) SAVF(CPANDO/CP1000) RSTLIB(YOURLIB)

substituting appropriate values for SAVF(CPANDO/CP1000) and RSTLIB(YOURLIB).


cp1000.savf - Table-driven Generic File Comparison


Valid HTML 3.2! Creative Commons License

BrilligWare/ chris@pando.org / revised February 2005