Search

Sunday, October 28, 2012

ICETOOL Example - Matching and non matching records

Create files with matching and non-matching records

There are two input files containing lists of records, as follows:

Input File1

V
F
C
H
D

Input File2

K
H
C
V
M

How can we create output files for the following?

  • The records that appear in both File1 and File2
  • The records that appear only in File1
  • The records that appear only in File2

Below is an ICETOOL job that can do this match by using the SPLICE operator. SPLICE operator in ICETOOL helps to perform various file join and match operations. 


This can be done by adding an identifier of '11' to the File1 records, add an identifier of '33' to the File2 records, and splice the second id byte for matching records so we get '13' for records in both files, '11' for records only in File1 and '33' for records only in File2.

//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DSN=... input File1
//IN2 DD DSN=... input File2
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(TRK,(5,5))
//* USE MOD FOR T1
// DISP=(MOD,PASS)
//OUT13 DD SYSOUT=* records in File1 and File2
//OUT1 DD SYSOUT=* records in File1 only
//OUT3 DD SYSOUT=* records in File2 only
//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,1*,CH) WITH(13,1) -
USING(CTL3) KEEPNODUPS
/*
//CTL1CNTL DD *
* Mark FILE1 records with '11'
INREC OVERLAY=(12:C'11')
/*
//CTL2CNTL DD *
* Mark FILE2 records with '33'
INREC OVERLAY=(12:C'33')
/*
//CTL3CNTL DD *
**** Write matching records to OUT13 file and removes id.
OUTFIL FNAMES=OUT13,INCLUDE=(12,2,CH,EQ,C'13'),BUILD=(1,1*)

**** Write FILE1 only records to OUT1 file and removes id.
OUTFIL FNAMES=OUT1,INCLUDE=(12,2,CH,EQ,C'11'),BUILD=(1,1*)

**** Write FILE2 only records to OUT3 file and removes id.
OUTFIL FNAMES=OUT3,INCLUDE=(12,2,CH,EQ,C'33'),BUILD=(1,1*)
/*

The output files will have the following records:
OUT13
C
H
V

OUT1
F
D

OUT3
K
M

2 comments:

  1. Can't we use JOIN KEYS to get the expected result even easily.

    Sreenivas,
    http://clearmainframeinterview.blogspot.in/2014/03/mainframe-interview-working-with.html

    ReplyDelete
  2. I appreciate this solution, as our shop is way behind on upgrades and our SORT version does not support JOINKEYS. ICETOOL is the best way for me to do a number of things.

    ReplyDelete