| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| WallaceC Beginner
 
 
 Joined: 17 Dec 2002
 Posts: 22
 Topics: 10
 
 
 | 
			
				|  Posted: Sat Jan 22, 2005 1:26 pm    Post subject: Compare & Merge Duplicate Records From 2 Files |   |  
				| 
 |  
				| I have 2 files with the same layout: 
 
  	  | Code: |  	  | FLD_A  CHAR(05)
 FLD_B  S9(09) COMP
 FLD_C  CHAR(04)
 
 | 
 TASK A
 Compare them and create 2 files with the following information:
 
 1. Same FLD_A & FLD_B but different FLD_C in File A & File B (only 1 matching record from each file)
 2. Same FLD_A & FLD_B but different FLD_C in File A & File B (If more than 1 matching record from either of each file)
 
 For example (FLD_B SHOWN AS NUMERIC FOR DISPLAY):
 
  	  | Code: |  	  | File A: A     B    C
 ----- ---- ----
 AAAAA 1111 ABCD
 BBBBB 2222 ABCD
 CCCCC 3333 ABCD
 DDDDD 4444 ABCD
 DDDDD 4444 DCBA
 EEEEE 5555 EEEE
 
 
 File B:
 A     B    C
 ----- ---- ----
 AAAAA 1111 DDDD
 BBBBB 2222 ABCD
 CCCCC 3333 AAAA
 CCCCC 3333 BBBB
 DDDDD 4444 DDDD
 EEEEE 5555 FFFF
 
 
 Expected output file A:
 A     B    C
 ----- ---- ----
 AAAAA 1111 ABCD
 AAAAA 1111 DDDD
 EEEEE 5555 EEEE
 EEEEE 5555 FFFF
 
 
 Expected output file B:
 A     B    C
 ----- ---- ----
 CCCCC 3333 ABCD
 CCCCC 3333 AAAA
 CCCCC 3333 BBBB
 DDDDD 4444 ABCD
 DDDDD 4444 DCBA
 DDDDD 4444 DDDD
 
 | 
 
 TASK B
 Convert output file A into output file C:
 
 1. With records with same FLD_A and FLD_B, append FLD_C from the second record into the first record
 
 Expected output file C:
 
  	  | Code: |  	  | A     B    C    C ----- ---- ---- ----
 AAAAA 1111 ABCD DDDD
 EEEEE 5555 EEEE FFFF
 
 | 
 Besides writing a COBOL program, could anyone tell if there is anyway to do the tasks above using SORT?
 
 Thanks,
 
 Wallace
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Phantom Data Mgmt Moderator
 
  
 
 Joined: 07 Jan 2003
 Posts: 1056
 Topics: 91
 Location: The Blue Planet
 
 | 
			
				|  Posted: Mon Jan 24, 2005 2:47 am    Post subject: |   |  
				| 
 |  
				| Wallace, 
 Any idea on the maximum number of duplicate records (File A + File B combined) that can occur ? or is that un-predicatable ?  Getting output A is easy in sort, but the output B is a bit tricky - atleast for the version of sort that I have.
 
 Thanks,
 Phantom
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| WallaceC Beginner
 
 
 Joined: 17 Dec 2002
 Posts: 22
 Topics: 10
 
 
 | 
			
				|  Posted: Mon Jan 24, 2005 5:23 am    Post subject: |   |  
				| 
 |  
				| Hi Phantom, 
 For every record on File A, the possible range of duplicate records on File B is 0 to 3.
 
 Thanks,
 
 Wallace
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| vivek Beginner
 
 
 Joined: 15 Jul 2004
 Posts: 95
 Topics: 11
 Location: Edison,NJ
 
 | 
			
				|  Posted: Tue Jan 25, 2005 9:59 am    Post subject: |   |  
				| 
 |  
				| wallace, From what I see in your description. 
 BBBBB 2222 ABCD  is not written to any file. So you want to get rid of row that are unique ?
 _________________
 Vivek,NJ
 
 Db2,IDMS
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| vivek Beginner
 
 
 Joined: 15 Jul 2004
 Posts: 95
 Topics: 11
 Location: Edison,NJ
 
 | 
			
				|  Posted: Tue Jan 25, 2005 10:05 am    Post subject: |   |  
				| 
 |  
				| Wallace, confirm my previous post. 
 for your task B to create field D and retain field C in same position along with A,B a similar thread is here.
 http://www.mvsforums.com/helpboards/viewtopic.php?t=10
 
 I did a similar job where in you create
 
 field A field B field C and the rest of the bytes are binary.
 similar modify second file to
 field A Field B Make it binary for rowlength equal to field C and then put field D.
 Then sum them with Binary option.
 
 the thread should have all details. Go thru it with patience. let me know if you have Q.
 _________________
 Vivek,NJ
 
 Db2,IDMS
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| vivek Beginner
 
 
 Joined: 15 Jul 2004
 Posts: 95
 Topics: 11
 Location: Edison,NJ
 
 | 
			
				|  Posted: Tue Jan 25, 2005 12:36 pm    Post subject: |   |  
				| 
 |  
				|  	  | Code: |  	  | File A:
 A     B    C    D
 ----- ---- ---- -
 AAAAA 1111 ABCD 1
 BBBBB 2222 ABCD 1
 CCCCC 3333 ABCD 1
 DDDDD 4444 ABCD 1
 DDDDD 4444 DCBA 1
 EEEEE 5555 EEEE 1
 
 
 File B:
 A     B    C    D
 ----- ---- ---- -
 AAAAA 1111 DDDD 1
 BBBBB 2222 ABCD 1
 CCCCC 3333 AAAA 1
 DDDDD 4444 DDDD 1
 EEEEE 5555 FFFF 1
 
 | 
 
 
 FILE X:  Concate file A and B and do a sum on column D, don
 _________________
 Vivek,NJ
 
 Db2,IDMS
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| vivek Beginner
 
 
 Joined: 15 Jul 2004
 Posts: 95
 Topics: 11
 Location: Edison,NJ
 
 | 
			
				|  Posted: Tue Jan 25, 2005 12:38 pm    Post subject: |   |  
				| 
 |  
				| Wallace , dont change the order of files in sort in and dont forget to use the EQUALS clause. This makes sure that the order of SORTIN rows do not change. 
 Check the actual sort fields, since this is just an example.
 
 Hope this helps and post me any problems you may have.
 
 Thanks,
 _________________
 Vivek,NJ
 
 Db2,IDMS
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| WallaceC Beginner
 
 
 Joined: 17 Dec 2002
 Posts: 22
 Topics: 10
 
 
 | 
			
				|  Posted: Tue Jan 25, 2005 7:06 pm    Post subject: |   |  
				| 
 |  
				| Hi Vivek, 
 Sorry to reply so late because I just got access to the site. Thanks for catching the missing row of BBBBB 2222 ABCD--it should be put onto output file B because they do not match to Rule # 1. For your suggestions I will try and keep you posted how they go when I get access to the system.
 
 Thanks again,
 
 Wallace
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| vivek Beginner
 
 
 Joined: 15 Jul 2004
 Posts: 95
 Topics: 11
 Location: Edison,NJ
 
 | 
			
				|  Posted: Tue Jan 25, 2005 9:06 pm    Post subject: |   |  
				| 
 |  
				| Wallace, then you should create FILE TWo2 using include cond=(sum field eq 2,zd)
 and create Multi file using include cond = (sum field ne 2,zd) . So the row BBBB will be in the multi file which has rows that are exactly present once in file A and B.
 
 I am sure this will work. Because of time constraint i have provided only the required jcl steps and briefed other steps in english.  do post here incase you may have trouble.
 
 lemme know how it goes if you crack it in first shot.
 It is always a good thing to post that your problem got solved.
 
 If you have trouble make sure you post whole jcl or concerned code and i have been thru times where I post something here and have a typo in my code.
 
 thanks,
 _________________
 Vivek,NJ
 
 Db2,IDMS
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  | 
	
		|  |