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 sort

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


Joined: 02 Oct 2021
Posts: 17
Topics: 7

PostPosted: Sun Oct 29, 2023 1:33 pm    Post subject: Merge two files and sort Reply with quote

Input File1(Key is 1st 6 positions):

Code:

KEY001FILE1............
KEY002FILE1............
KEY003FILE1............


Input File2(Key is 1st 6 positions):

Code:

KEY001FILE2..............................
KEY001FILE2..............................
KEY001FILE2..............................
KEY002FILE2..............................
KEY002FILE2..............................
KEY003FILE2..............................
KEY003FILE2..............................
KEY003FILE2..............................
KEY003FILE2..............................


Desired Output:

Code:

KEY001FILE1............
KEY001FILE2..............................
KEY001FILE2..............................
KEY001FILE2..............................
KEY002FILE1............
KEY002FILE2..............................
KEY002FILE2..............................
KEY003FILE1............
KEY003FILE2..............................
KEY003FILE2..............................
KEY003FILE2..............................
KEY003FILE2..............................


File 1 Sort:
Code:

  SORT FIELDS=(1,6,CH,A)
  INREC BUILD=(1,6,7:1511C' ',C'A')


File 2 Sort:
Code:

  SORT FIELDS=(1,6,CH,A)
  INREC BUILD=(1,1517,C'B')


Merge Both files and Sort:
Code:

  SORT FIELDS=(1,30,CH,A,1518,1,CH,A)
Back to top
View user's profile Send private message
erasani
Beginner


Joined: 02 Oct 2021
Posts: 17
Topics: 7

PostPosted: Sun Oct 29, 2023 2:59 pm    Post subject: Reply with quote

Hi All,

I have shown the Input files and the Desired output. Currently i am achieving the desired output in 3 steps. Shown them above. Please let me know if all these steps can be combined in one?

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


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

PostPosted: Mon Oct 30, 2023 1:25 am    Post subject: Reply with quote

erasani,

What is the LRECL and RECFM of the files? You control cards do NOT make any sense as the first 2 sorts are sorting on 1,6,CH,A , what is the point of sorting on 1,30,CH,A in the merge step? Why not change the first 2 steps to be 1,30,CH,A and use COPY on the third while merging?
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

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


Joined: 02 Oct 2021
Posts: 17
Topics: 7

PostPosted: Mon Oct 30, 2023 8:08 am    Post subject: Reply with quote

Hi Kolusu,

Sorry for the confusion. I was trying to simplify the lengths and made a mess.

Just to summarize,
1) File 1 length is 147. This file will have one record per key. I am adding 1370 spaces and adding 'A' at the end for final sorting.
2) File 2 length is 1517. This file will have multiple records per key. I am adding 'B' at the end for final sorting. Key is 30 bytes in both the cases. After step 1 and step 2, the file lengths are 1518.
3) In the final step, i am trying to sort with 1,30 and 1517,1.

It takes 3 steps to achieve the desired output. I need to process the merged file in a COBOL program. Can we achieve the desired output in one step?

File 1 Length - 147. Key length - 30.
Code:

SORT FIELDS=(1,30,CH,A)
INREC BUILD=(1,147,148:1370C' ',C'A')


File 2 Length - 1517. Key length - 30.
Code:

SORT FIELDS=(1,30,CH,A)
INREC BUILD=(1,1517,C'B')


Merged File Length - 1518.
Code:

SORT FIELDS=(1,30,CH,A,1518,1,CH,A)
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Nov 01, 2023 7:35 am    Post subject: Reply with quote

erasani,

You can use Joinkeys to merge the 2 files together.
Code:

//STEP0100 EXEC PGM=SORT       
//SYSOUT   DD SYSOUT=*         
//INA      DD DISP=SHR,DSN=Your.Input.FB.1517.LRECL.file
//INB      DD DISP=SHR,DSN=Your.Input.FB.0147.LRECL.file
//SYSIN    DD *                                           
  OPTION COPY                                             
  JOINKEYS F1=INA,FIELDS=(1,30,A)                         
  JOINKEYS F2=INB,FIELDS=(1,30,A)                         
  JOIN UNPAIRED                                           
  REFORMAT FIELDS=(F1:01,1517,                           
                   F2:01,0147,                           
                   ?),FILL=X'40'
                                                         
  INREC IFTHEN=(WHEN=(1665,1,CH,EQ,C'2'),                 
             OVERLAY=(0001:1518,0147))                   
                                                         
  OUTREC OVERLAY=(1667:SEQNUM,5,ZD,RESTART=(01,30))       
                                                         
  OUTFIL IFOUTLEN=1517,                                   
  IFTHEN=(WHEN=(1665,01,CH,EQ,C'B',AND,1667,05,ZD,EQ,1), 
         BUILD=(1518,0147,/,                             
                0001,1517))                               
/*                                                       

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

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


Joined: 02 Oct 2021
Posts: 17
Topics: 7

PostPosted: Wed Nov 01, 2023 6:51 pm    Post subject: Reply with quote

Thanks kolusu for your help
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