Compare two files on mainframe using SyncSort.

Compare two files on mainframe using SyncSort

As we talked about comparing two files using DFSORT and writing matched and unmatched records to the output, in this post we’ll address the same question that compare two files on mainframe using SyncSort and write the match & no-match records.

 

For the below example some consideration are as follows:

  1. Files are fixed-block, RECFM=FB
  2. Files length is 80, LRECL=80
  3. The key on which the files are compared starts at position and are 7 characters long.

With above attributes, the following SORT statements should get you what you want:

JOINKEYS FILE=F1,FIELDS=(key1startpos,7,A)
JOINKEYS FILE=F2,FIELDS=(key2startpos,7,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,80,F2:1,80)
SORT FIELDS=COPY

We need the matched and non-matched records in different files.  For this in  DFSORT, there is a matching-marker, specified with ? in the REFORMAT, as discussed in the other topic.

But SyncSort does not have this “match marker” available. The absence or presence of data on the REFORMAT record has to be determined by values. Pick a byte on both input records which cannot contain a particular value (for instance, within a number, decide on a non-numeric value). Then specify that value as the FILL character on the REFORMAT.

REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'

If position 1 on F1 does not have “#” as part of data and position 20 on F2 cannot either, then those two positions can be used to establish the result of the match. The entire record can be tested if necessary, but you end up payin gfor more CPU. SyncSort, output unmatched records:

 

REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'
OUTFIL FNAMES=NOMATCH,INCLUDE=(1,1,CH,EQ,C'#',
OR,100,1,CH,EQ,C'#'),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),
BUILD=(1,80)),
IFTHEN=(WHEN=NONE,
BUILD=(81,80))

Collecting all the pieces, the code for SyncSort would look like this:

JOINKEYS FILE=F1,FIELDS=(1,7,A)
JOINKEYS FILE=F2,FIELDS=(1,7,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=C'#'
SORT FIELDS=COPY
OUTFIL FNAMES=NOMATCH,INCLUDE=(1,1,CH,EQ,C'#',
OR,100,1,CH,EQ,C'#'),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),
BUILD=(1,80)),
IFTHEN=(WHEN=NONE,
BUILD=(81,80))
OUTFIL FNAMES=MATCH,SAVE,
BUILD=(1,80)