MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Match & Replace

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Sun Feb 27, 2011 12:27 pm    Post subject: Match & Replace Reply with quote

hi,

I've two files FILE1 and FILE2. LRECL=80 for both the files. I've to compare the two files on the first 10bytes & merge the records, write the records to FILE3. if the record exists only in FILE1 or only in FILE2, then write it to FILE3. If a record exist in both the files(first 10 bytes might match,but other fields will have different values), then copy data from FILE2 & write to FILE3. please note that first 10bytes can have duplicates.
for eg.,
data in FILE1:
1111111111 aaaaaaa
1111111111 bbbbbbb
2222222222 cccccccc

data in FILE2:
1111111111 xxxxxxxx
2222222222 yyyyyyyy
3333333333 zzzzzzzzz

FILE3:
1111111111 xxxxxxxx
2222222222 yyyyyyyy
3333333333 zzzzzzzzz

appreciate your help.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Feb 28, 2011 11:21 am    Post subject: Reply with quote

koolspark,

Use the following DFSORT JCL which will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT                         
//SYSOUT   DD SYSOUT=*                           
//INA      DD *                                   
1111111111 AAAAAAA                               
1111111111 BBBBBBB                               
2222222222 CCCCCCCC                               
//INB      DD *                                   
----+----1----+----2----+----3----+----4----+----5
1111111111 XXXXXXXX                               
2222222222 YYYYYYYY                               
3333333333 ZZZZZZZZZ                             
//SORTOUT  DD SYSOUT=*                           
//SYSIN    DD *                                   
  OPTION COPY                                     
  JOINKEYS F1=INA,FIELDS=(1,10,A)                 
  JOINKEYS F2=INB,FIELDS=(1,10,A)                 
  JOIN UNPAIRED
  REFORMAT FIELDS=(F2:1,80,?,F1:1,80)                               
  INREC IFOUTLEN=80,IFTHEN=(WHEN=(81,1,CH,EQ,C'1'),BUILD=(82,80))   
//JNF1CNTL DD *                                   
  SUM FIELDS=NONE 
//JNF2CNTL DD *       
  SUM FIELDS=NONE                                   
//*
Back to top
View user's profile Send private message Send e-mail Visit poster's website
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Tue Mar 01, 2011 6:03 am    Post subject: Reply with quote

Kolusu,
thanks for your time, but I'm not getting unmatched records from INA file. I need all unmatched records also from both INA & INB files and if a match is found then i should copy the record from INB file to the output.
for eg:
INA file:
1111111111 aaaaaaaaaa
1111111111 bbbbbbbbbb
2222222222 ccccccccccc
2222222222 dddddddddd
4444444444 eeeeeeeeee

INB file:
1111111111 xxxxxxxxxx
1111111111 vvvvvvvvvv
2222222222 yyyyyyyyyy
3333333333 zzzzzzzzzzz

My output file should look like:
1111111111 xxxxxxxxxx (since i have a match in INA & INB for first 10 bytes, 1111111111 vvvvvvvvvv copy the data from INB. ignore record from INA)
2222222222 yyyyyyyyyy
3333333333 zzzzzzzzzzz (unmatched record from file2)
4444444444 eeeeeeeeee (unmatched record from file1)

The file should be sorted on first 10bytes and both INA & INB files can have duplicates in the first 10 bytes.

Thanks,
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Mar 01, 2011 9:17 am    Post subject: Reply with quote

koolspark,

Did you copy the control cards as is? If you did and still not get the desired results, then I would like to see the complete sysout from the job

Quote:
1111111111 xxxxxxxxxx (since i have a match in INA & INB for first 10 bytes, 1111111111 vvvvvvvvvv copy the data from INB. ignore record from INA)


In your output you show only 1 record for match and what exactly do I need to copy from the VVVVVVV record?
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Tue Mar 01, 2011 10:42 am    Post subject: Reply with quote

kolusu,

If i find a match, then i should copy the data from the second file to output. I should not copy the data from first file.

INA file:
1111111111 aaaaaaaaaa
1111111111 bbbbbbbbbb

INB file:
1111111111 xxxxxxxxxx
1111111111 vvvvvvvvvv

in this case, we have a match(first 10 bytes). so copy the data from INB to the output. so my output should have data from INB file.

output:
1111111111 xxxxxxxxxx
1111111111 vvvvvvvvvv

along with this, i need to copy all unmatched rows from both the files INA & INB.
in simple, my output file should contain all unmatchted rows from both INA & INB files and matched rows from INB file.

Thanks,
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Mar 01, 2011 11:27 am    Post subject: Reply with quote

koolspark,

You did not answer my question. Did you copy the control cards as is and if so what is the result? Why aren't you showing the sysout from the run?

You change your requirements with every post. Now you want the duplicates from file 2? I can't be providing solutions with a moving target.

If you require the duplicates from file 2 then remove the JNF2CNTL statement which removes the duplicates. What happens to the non-match duplicates from file 1?

Use this JCL to capture both file duplicates

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//INA      DD *                                                     
1111111111 AAAAAAA                                                 
1111111111 BBBBBBB                                                 
2222222222 CCCCCCCC                                                 
4444444444 MISSING - 1                                             
4444444444 MISSING - 2                                             
//INB      DD *                                                     
1111111111 XXXXXXXX                                                 
1111111111 AAAAAAAA                                                 
2222222222 YYYYYYYY                                                 
3333333333 ZZZZZZZZZ                                               
5555555555 LLLLLLLLL NO MATCH1                                     
5555555555 MMMMMMMMM NO MATCH2                                     
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  OPTION COPY                                                       
  JOINKEYS F1=INA,FIELDS=(1,10,A)                                   
  JOINKEYS F2=INB,FIELDS=(1,10,A)                                   
  JOIN UNPAIRED                                                     
  REFORMAT FIELDS=(F2:1,80,?,F1:1,80)                               
  INREC IFOUTLEN=80,IFTHEN=(WHEN=(81,1,CH,EQ,C'1'),BUILD=(82,80))   
//*


The output from this is
Code:

1111111111 XXXXXXXX             
1111111111 AAAAAAAA             
1111111111 XXXXXXXX             
1111111111 AAAAAAAA             
2222222222 YYYYYYYY             
3333333333 ZZZZZZZZZ             
4444444444 MISSING - 1           
4444444444 MISSING - 2           
5555555555 LLLLLLLLL NO MATCH1   
5555555555 MMMMMMMMM NO MATCH2   

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Tue Mar 01, 2011 12:43 pm    Post subject: Reply with quote

kolusu,
I'm really sorry failing to put forward my requirement clearly. with your first solution, i was missing the unmatched records from the first file in my output. also, i was not getting the duplicates from file2 in the output. I needed all the unmatched unique/duplicates from both the files plus the matched unique/duplicate records from file2.
for eg., if i have 10 records for key 1111111111 in file1 and 2 records for the same key 1111111111 in file2 then my output should have the 2 records from file2. It should not copy any of the 10 records from file1.

I'm out of office and don't have access to mainframe, so i'm not able to post the sysout from the job run.
once again thank you verymuch for the support you are providing to the mainframe community..

Thanks,
Back to top
View user's profile Send private message
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Tue Mar 01, 2011 12:47 pm    Post subject: Reply with quote

INA
Code:
 
1111111111 AAAAAAA                                                 
1111111111 BBBBBBB                                                 
2222222222 CCCCCCCC                                                 
4444444444 MISSING - 1                                             
4444444444 MISSING - 2                                             

INB
Code:

1111111111 XXXXXXXX                                                 
1111111111 AAAAAAAA                                                 
2222222222 YYYYYYYY                                                 
3333333333 ZZZZZZZZZ                                               
5555555555 LLLLLLLLL NO MATCH1                                     
5555555555 MMMMMMMMM NO MATCH2

output should be:
Code:

1111111111 XXXXXXXX             
1111111111 AAAAAAAA             
2222222222 YYYYYYYY             
3333333333 ZZZZZZZZZ             
4444444444 MISSING - 1           
4444444444 MISSING - 2           
5555555555 LLLLLLLLL NO MATCH1   
5555555555 MMMMMMMMM NO MATCH2
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Tue Mar 01, 2011 3:37 pm    Post subject: Reply with quote

Which release of the sort is being used?
_________________
All the best,

di
Back to top
View user's profile Send private message
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Wed Mar 02, 2011 12:45 am    Post subject: Reply with quote

papadi,

we are using 'Z/OS DFSORT V1R10'

Thanks,
Back to top
View user's profile Send private message
koolspark
Beginner


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Wed Mar 16, 2011 8:47 am    Post subject: Reply with quote

any help?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Mar 17, 2011 2:48 pm    Post subject: Reply with quote

koolspark,

I am not sure as to what kind help you are looking for because you seem to change the requirements as you please.

The following DFSORT JCL will give you the desired results. I assumed that your input is already sorted on the key in pos 1 thru 10 bytes. If it is not then you need an additional pass to get the information. Let me know if that is the case and I will show you a different solution.

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//INA      DD *                                                   
1111111111 AAAAAAA                                               
1111111111 BBBBBBB                                               
2222222222 CCCCCCCC                                               
4444444444 MISSING - 1                                           
4444444444 MISSING - 2                                           
//INB      DD *                                                   
1111111111 XXXXXXXX                                               
1111111111 AAAAAAAA                                               
2222222222 YYYYYYYY                                               
3333333333 ZZZZZZZZZ                                             
5555555555 LLLLLLLLL NO MATCH1                                   
5555555555 MMMMMMMMM NO MATCH2                                   
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  JOINKEYS F1=INA,FIELDS=(1,10,A,81,8,A),SORTED,NOSEQCK           
  JOINKEYS F2=INB,FIELDS=(1,10,A,81,8,A),SORTED,NOSEQCK           
  JOIN UNPAIRED                                                   
  REFORMAT FIELDS=(F2:1,80,?,F1:1,80)                             
  INREC IFOUTLEN=80,IFTHEN=(WHEN=(81,1,CH,EQ,C'1'),BUILD=(82,80))
//JNF1CNTL DD *                                                   
  INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,10))                   
//JNF2CNTL DD *                                                   
  INREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,10))                   
//*

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group