View previous topic :: View next topic
Author
Message
vina2010 New User Joined: 06 Sep 2010Posts: 19 Location: Bangalore
Hi
I have a requirement to remove duplicates from two different file if it has duplicates in two different files not in the same. If the duplicates are in the same file then the duplicates should not be removed.
For Example:
File 1 has
AAAAAAA,1234
ZZZZZZZ,3452
File 2 has
AAAAAAA,1234
BBBBBBB,2345
BBBBBBB,2345
CCCCCC,5678
File 3 should have
BBBBBBB,2345
BBBBBBB,2345
CCCCCC,5678
ZZZZZZZ,3452
(order is not important)
Can anyone please guide to acheive this via JCL sorts? I need to consider both the fields in the sort separated by comma.
Back to top
elango_K New User Joined: 18 Aug 2011Posts: 44 Location: India
This can be achieved using JOINKEYS.
Code:
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(1,12,A)
JOINKEYS FILE=F2,FIELDS=(1,12,A)
JOIN UNPAIRED,F1,F2,ONLY
REFORMAT FIELDS=(F1:1,12,F2:1,12)
OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,24)),
IFTHEN=(WHEN=(1,1,CH,EQ,C' '),BUILD=(1:13,12))
OUTFIL FNAMES=SORTOUT,REMOVECC,BUILD=(1,12)
//*
Output
Code:
BBBBBBB,2345
BBBBBBB,2345
CCCCCCC,5678
ZZZZZZZ,3452
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Here are two more ways to do it with DFSORT's JOINKEYS (I assumed the input files have FB/80):
Code:
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD DSN=... input file1 (FB/80)
//IN2 DD DSN=... input file2 (FB/80)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
JOINKEYS F1=IN1,FIELDS=(1,15,A)
JOINKEYS F2=IN2,FIELDS=(1,15,A)
JOIN UNPAIRED,F1,F2,ONLY
REFORMAT FIELDS=(F1:1,80,F2:1,80,?)
OPTION COPY
INREC IFTHEN=(WHEN=(161,1,CH,EQ,C'1'),BUILD=(1,80)),
IFTHEN=(WHEN=NONE,BUILD=(81,80))
/*
Code:
//S2 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD DSN=... input file1 (FB/80)
//IN2 DD DSN=... input file2 (FB/80)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
JOINKEYS F1=IN1,FIELDS=(1,15,A)
JOINKEYS F2=IN2,FIELDS=(1,15,A)
JOIN UNPAIRED,F1,F2,ONLY
OPTION COPY
OUTFIL VTOF,BUILD=(5,80)
/*
Back to top
Please enable JavaScript!