1) Compare two files and write all matching records to output file. (INNER JOIN - ONLY MATCHING ROWS)
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOINKEYS FILE=F1,FIELDS=(1,5,A)
REFORMAT FIELDS=(F1:1,13,F2:1,12)
SORT FIELDS=COPY
//*
OUTPUT:
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI
=======================================================================
2) Compare two files and write matching as well as non-matching rows from File1 (LEFT OUTER JOIN - Matching and non-matching from F1)
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:01,13,F2:01,12)
SORT FIELDS=COPY
//*
OUTPUT
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI
21600 KULDIP
21800 MANDIP
21900 BALDIP
=======================================================================
3) Compare two files and write NON-MATCHING rows from F1 ONLY.
F2 we should not use in REFORMAT it will blank values
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F1,ONLY
REFORMAT FIELDS=(F1:01,13)
SORT FIELDS=COPY
//*
OUTPUT:
21600 KULDIP
21800 MANDIP
21900 BALDIP
=======================================================================
4) Compare two files and write matching as well as non-matching rows from File2 (RIGHT OUTER JOIN - Matching and non-matching from F2)
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:01,13)
SORT FIELDS=COPY
//*
OUTPUT:
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
=======================================================================
5) Compare two files and write ONLY non-matching rows from File2
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F2,ONLY
REFORMAT FIELDS=(F2:01,13)
SORT FIELDS=COPY
//*
OUTPUT:
22100 THANE
22200 KALYAN
=======================================================================
6) Compare two files and write matching as well non-matching rows (FULL OUTER JOIN)
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//MATCH DD SYSOUT=*
//NOMATCH1 DD SYSOUT=*
//NOMATCH2 DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED=F1,F2
REFORMAT FIELDS=(F1:01,13,
F2:01,13,?)
SORT FIELDS=COPY
*
OUTFIL FNAMES=MATCH,
INCLUDE=(27,01,CH,EQ,C'B'),
BUILD=(01,27,)
*
OUTFIL FNAMES=NOMATCH1,
INCLUDE=(27,01,CH,EQ,C'1'),
BUILD=(01,13,27,01)
*
OUTFIL FNAMES=NOMATCH2,
INCLUDE=(27,01,CH,EQ,C'2'),
BUILD=(14,13,27,01)
//*
OUTPUT:
MATCH:
21400 SANDIP 21400 PUNE B
21500 RANDIP 21500 MUMBAI B
NOMATCH1:
21600 KULDIP 1
21800 MANDIP 1
21900 BALDIP 1
NOMATCH2:
22100 THANE 2
22200 KALYAN 2
*****Similar type to above ****
Write matching and unmatching both records from both files in two output files -
//SORTJNF1 DD *
21400 SANDIP PUNE
21500 BALDIP MUMBAI
21600 KULDIP HYDERABAD
21700 RANDIP THANE
//SORTJNF2 DD *
21400 TIETO
21700 SYNTEL
21800 TCS
21900 HSBC
//MATCH DD SYSOUT=*
//NOMTACH DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
REFORMAT FIELDS=(F1:01,25,F2:01,15,?)
SORT FIELDS=COPY
OUTFIL FNAMES=MATCH,INCLUDE=(41,01,CH,EQ,C'B'),
BUILD=(01,40,40X)
OUTFIL FNAMES=NOMATCH,INCLUDE=(41,01,CH,EQ,C'1',OR,
41,01,CH,EQ,C'2'),
IFTHEN=(WHEN=(41,CH,EQ,C'1'),BUILD=(1,25)),
IFTHEN=(WHEN=(41,CH,EQ,C'2'),BUILD=(26,15))
//*
MATCH OUTPUT
21400 SANDIP PUNE 21400 TIETO
21600 KULDIP THANE 21700 SYNTEL
NOMATCH OUTPUT
21500 BALDIP MUMBAI
21600 KULDIP HYDERABAD
21800 TCS
21900 HSBC
=======================================================================
7) Compare two files and write ONLY non-matching rows from F1 & F2
//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SORTOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(1,5,A)
JOINKEYS FILE=F2,FIELDS=(1,5,A)
JOIN UNPAIRED=F1,F2,ONLY
REFORMAT FIELDS=(F1:01,13,
F2:01,13,?)
SORT FIELDS=COPY
OUTPUT:
MATCH:
21600 KULDIP 1
21800 MANDIP 1
21900 BALDIP 1
22100 THANE 2
22200 KALYAN 2
1 in the output file is printed because "?" was given in REFROMAT FIELDS.
==================================================