Page 1 of 1

merge the records from 3 input files into 1 output file alte

PostPosted: Sun Jan 24, 2016 10:45 am
by MFUSERVDC
I want to merge the records from 3 input files into 1 output file alternately using sort in JCL. Below are the details
Input File1 :--
  Rec1 ABBBB
       BCCCC
       DEEEE
  Rec2 BDDDD
       DFFFF
       RTTTT

Input File2 :--
  Rec1 SGGHH
       YTTTT
       DWWWW
  Rec2 QEEEE
       DRRRR
       RYYYY

Input File3 :--
  Rec1 URTRT
       ATTTT
       DSSSS
  Rec2 REEEY
       DIYUU
       REDER


Output File :--
  Rec1 ABBBB
       BCCCC
       DEEEE
  Rec1 SGGHH
       YTTTT
       DWWWW
  Rec1 URTRT
       ATTTT
       DSSSS
  Rec2 BDDDD
       DFFFF
       RTTTT
  Rec2 QEEEE
       DRRRR
       RYYYY
  Rec2 REEEY
       DIYUU
       REDER


I tried the some sort cards for merge alternately but its merging record after record. However I want to merge 1st few records from 1st files and then from 2nd and then from 3rd (as explained above example).
Please help me in this (asap).

Thanks,
MFUSERVDC

Code'd

Re: merge the records from 3 input files into 1 output file

PostPosted: Sun Jan 24, 2016 4:03 pm
by Aki88
Hello,

One way of doing it can be (and this is assuming, the 3 files have same LRECL, and are FB and when you say REC1 or REC2 of any file you mean record 1 or 2- and the three lines of data actually appear in 1 line), using ICETOOL, copy data from each file into a TEMP file - during this process temporarily extend the record using INREC and add SEQNUM to the end of the record; following on, after the copy of data to TEMP file with SEQNUM added, have a SORT FIELDS step which sorts the data on the SEQNUM; while writing the record to output file, BUILD the record excluding SEQNUM.
That should do the trick, as all the three files will have records arranged in sequence, so when the final SORT FIELDS will actually run, it'll group the data according to the individual sequence numbers.

Hth.

Re: merge the records from 3 input files into 1 output file

PostPosted: Sun Jan 24, 2016 7:30 pm
by NicC
See my post in response to the same query under Syncsort.

Re: merge the records from 3 input files into 1 output file

PostPosted: Sun Jan 24, 2016 10:14 pm
by MFUSERVDC
Hi Aki88,
Thanks for quick reply.
I guess, the logic you explained in above post is perfect when 3 lines of data appearing in 1 record. But I want to merge group (some lines ) of data from 1st file and then some lines from 2nd and similarly from 3rd input file into one output file. This is not happening with above logic.

Thanks,
MFUSERVDC