Example 3 - Create files with matching and non-matching records
This example shows how you can match records in input data sets
1 and 2 to produce three output data sets with:
- ON fields that appear in both input data set 1 and input data set 2
- ON fields that appear only in input data set 1
- ON fields that appear only in input data set 2
//S3 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
Vicky
Frank
Carrie
Holly
Paul
/*
//IN2 DD *
Karen
Holly
Carrie
Vicky
Mary
/*
//OUT12 DD SYSOUT=*
//OUT1 DD SYSOUT=*
//OUT2 DD SYSOUT=*
//T1 DD DSN=&&T1,DISP=(MOD,PASS),UNIT=SYSDA,SPACE=(TRK,(5,5))
//TOOLIN DD *
* Add '11' identifier for FILE1 records.
COPY FROM(IN1) TO(T1) USING(CTL1)
* Add '22' identifier for FILE2 records.
COPY FROM(IN2) TO(T1) USING(CTL2)
* SPLICE to match up records and write them to their
* appropriate output files.
SPLICE FROM(T1) TO(OUT12) ON(1,10,CH) WITH(13,1) -
USING(CTL3) KEEPNODUPS
/*
//CTL1CNTL DD *
* Mark FILE1 records with '11'
OUTREC FIELDS=(1,10,12:C'11')
/*
//CTL2CNTL DD *
* Mark FILE2 records with '22'
OUTREC FIELDS=(1,10,12:C'22')
/*
//CTL3CNTL DD *
* Write matching records to OUT12 file. Remove id.
OUTFIL FNAMES=OUT12,INCLUDE=(12,2,CH,EQ,C'12'),OUTREC=(1,10)
* Write FILE1 only records to OUT1 file. Remove id.
OUTFIL FNAMES=OUT1,INCLUDE=(12,2,CH,EQ,C'11'),OUTREC=(1,10)
* Write FILE2 only records to OUT2 file. Remove id.
OUTFIL FNAMES=OUT2,INCLUDE=(12,2,CH,EQ,C'22'),OUTREC=(1,10)
/*
We copy the IN1 records to the T1 data set and add an identifier of '11' to show they come from FILE1.
We copy the IN2 records to the end (MOD) of the T1 data set and add an identifier of '22' to show they come from FILE2.
We sort the records of T1 on positions 1-3 and splice the second id byte for matching records. We use KEEPNODUPS to keep non-duplicate records.
The records look like this after they are
sorted, but before they are spliced:
Carrie 11
Carrie 22
Frank 11
Holly 11
Holly 22
Karen 22
Mary 22
Paul 11
Vicky 11
Vicky 22
The records look like this after they are
spliced, but before we do the OUTFIL processing
specified by CTL3CNTL with USING(CTL3) for SPLICE:
Carrie 12
Frank 11
Holly 12
Karen 22
Mary 22
Paul 11
Vicky 12
An id of 12 indicates an ON field that appears in IN1 and IN2. An id of 11 indicates an ON field that appears only in IN1. An id of 22 indicates an ON field that appears only in IN2.
The OUTFIL statements in CTL3CNTL write the records to their appropriate output data sets (without the ids) as follows:
OUT12 contains:
Carrie
Holly
Vicky
OUT1 contains:
Frank
Paul
OUT2 contains:
Karen
Mary