Merge two files and sort
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Utilities

#1: Merge two files and sort Author: erasani PostPosted: Sun Oct 29, 2023 1:33 pm
    —
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)

#2:  Author: erasani PostPosted: Sun Oct 29, 2023 2:59 pm
    —
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

#3:  Author: kolusuLocation: San Jose PostPosted: Mon Oct 30, 2023 1:25 am
    —
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?

#4:  Author: erasani PostPosted: Mon Oct 30, 2023 8:08 am
    —
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)

#5:  Author: kolusuLocation: San Jose PostPosted: Wed Nov 01, 2023 7:35 am
    —
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))                               
/*                                                       

#6:  Author: erasani PostPosted: Wed Nov 01, 2023 6:51 pm
    —
Thanks kolusu for your help



MVSFORUMS.com -> Utilities


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group