View previous topic :: View next topic
Author
Message
Bhagyashree Panigrahi New User Joined: 03 Mar 2009Posts: 7 Location: Pune
Hi,
I need to compare 2 files and replace the field 2 in file 1 whenever a match is found in file 2 with the related field value. I have used ICETOOL SPLICE. However for more than 1 match (duplicates), the data is not getting replaced.
Example -
File 1 -
Code:
Field1 Key Field Field2
------------------------------------
ABC PPP 111
DEF QQQ 222
GHI QQQ 333
IJK RRR 444
Position of fields in file 1-
Field 1 - Pos 1, length - 12 bytes
Key Field - Pos 73,length - 6 bytes
Field 2 - Pos 79,length - 5 bytes
File 2 -
Code:
Key field Field2
-----------------------
QQQ XXX
RRR YYY
Position of fields in file 2-
Key Field - Pos 1,length - 6 bytes
Field 2 - Pos 7,length - 5 bytes
Output required -
Code:
Field1 Key field Field2
-------------------------------------
ABC PPP 111
DEF QQQ XXX
GHI QQQ XXX
IJK RRR YYY
Output I am getting is -
Code:
Field1 Key field Field2
-------------------------------------
ABC PPP 111
DEF QQQ XXX
GHI QQQ 333
IJK RRR YYY
JCL step -
Code:
//ICESTEP EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DISP=SHR, DSN= File1
//IN2 DD DISP=SHR, DSN=File 2
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(300,50),RLSE),
// DISP=(MOD,PASS)
//OUT12 DD DSN=Output file,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(100,50),RLSE)
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T1) USING(CTL2)
SPLICE FROM(T1) TO(OUT12) ON(13,6,CH) WITH(19,5) -
WITHALL KEEPNODUPS
/*
//CTL1CNTL DD *
OUTREC FIELDS=(1:1,12,13:73,11)
/*
//CTL2CNTL DD *
OUTREC FIELDS=(1:12X,13:1,6,19:7,5)
/*
Back to top
Skolusu Senior Member Joined: 07 Dec 2007Posts: 2205 Location: San Jose
Bhagyashree Panigrahi,
Which file has the duplicates? Does both files have duplicates?
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Bhagyashree,
Assuming file1 has duplicates and file2 doesn't, as shown in your example, here's a DFSORT/ICETOOL job that will do what you asked for:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DISP=SHR,DSN=File1
//IN2 DD DISP=SHR,DSN=File2
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(300,50),RLSE),
// DISP=(MOD,PASS)
//OUT DD DSN=Output file,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(100,50),RLSE)
//TOOLIN DD *
COPY FROM(IN2) TO(T1) USING(CTL1)
COPY FROM(IN1) TO(T1) USING(CTL2)
SPLICE FROM(T1) TO(OUT) ON(13,6,CH) WITH(1,18) -
WITHALL KEEPNODUPS
/*
//CTL1CNTL DD *
INREC BUILD=(13:1,6,19:7,5)
/*
//CTL2CNTL DD *
INREC BUILD=(1,12,13:73,6,19:79,5)
/*
Back to top
Bhagyashree Panigrahi New User Joined: 03 Mar 2009Posts: 7 Location: Pune
Thanks Frank.
Its working!
I have one question though, if we were to use OUTREC, what would be the syntax and if not, why shouldn't we use it? If possible, can you also explain what was the error in the JCL I had provided?
Thanks,
Bhagyashree
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
You can use OUTREC or INREC interchangeably here.
Since input file1 has duplicates and input file2 does not have duplicates, T1 must have the input file2 records followed by the input file1 records in order for WITHALL to work.
Notice that I do:
COPY IN2 to T1
COPY IN1 to T1
whereas you do:
COPY IN1 to T1
COPY IN2 to T1
That also changes the WITH field you need to use.
Back to top
Please enable JavaScript!