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 

Merge two files and keep original order

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


Joined: 15 Nov 2007
Posts: 3
Topics: 2

PostPosted: Fri May 30, 2014 11:35 am    Post subject: Merge two files and keep original order Reply with quote

Hi

I have two files and I want to do a MERGE of these two files but I want to keep the originally order.
Let me explain using an example:

File1
Code:

Field1      Field2
20140101A00001
20140101A00002
20140101A00004


File 2
Code:

Field1      Field2
20140201A00001
20140201A00002
20140201A00003
20140201A00004

I am Using the following instruction:
Code:

//JS040    EXEC PGM=ICEMAN,COND=(0,NE)         
//SYSOUT   DD SYSOUT=*                         
//SORTIN01 DD DSN=FILE1,                       
//            DISP=SHR                         
//SORTIN02 DD DSN=FILE2,                       
//            DISP=SHR                         
//SORTOUT  DD DSN=FILE3,                       
//             DISP=SHR                         
//SYSIN    DD *                                 
  MERGE FIELDS=(9,6,CH,A)
  SUM FIELDS=NONE                               


In FILE 3 I am obtaining the following result
Code:

Field1      Field2
20140101A00001
20140201A00002
20140201A00003
20140101A00004

(Note: The 1st and 4st record was obtained from the file 1, the 3rd record was obtained from file 2 because it only existed on that file, the records 2 that existed in file 1 and file 2 was obtained from file 2)


I was expecting to have:
Code:

Field1      Field2
20140101A00001
20140101A00002
20140201A00003
20140101A00004


(Note: The 1st and 4st record was obtained from the file 1, the 3rd record was obtained from file 2 because it only existed on that file, the records 2 that existed in file 1 and file 2 was obtained from file 1)

Could you please help me

Best Regards
Nuno Menezes
Ext 557470
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Fri May 30, 2014 11:43 am    Post subject: Reply with quote

If you use OPTION EQUALS or add EQUALS along with the MERGE key, the original order will be preserved, meaning in the case of MERGE that SORTIN01 records will be selected in preference to all the SORTINnn with higher numbers, SORTIN02 will be given preference over all the SORTINnn with higher numbers (where present), etc.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri May 30, 2014 11:58 am    Post subject: Reply with quote

nmenezes,

As William Pointed out you need the option EQUALS to retain the order of records.
Code:

//SYSIN    DD *                 
  MERGE FIELDS=(9,6,CH,A),EQUALS
  SUM FIELDS=NONE               
//*

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


Joined: 15 Nov 2007
Posts: 3
Topics: 2

PostPosted: Mon Jun 02, 2014 5:15 am    Post subject: Reply with quote

Thank you all for your help. It solved my problem.
Best regards
Nuno
Back to top
View user's profile Send private message
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