Page 1 of 1

Merge Files

PostPosted: Mon Aug 02, 2010 9:44 pm
by Gron
I am trying to use DFSORT to merge several files into one but retain only the first header record.
All the input files have the same format.

I have 6 fixed length flat files, each with the same format:
Header-rec
Detail-rec
Detail-rec
.
.
etc.

I want to merge the files but only retain one header rec.
The header record can be uniquely identified. #
I cannot use SUM FIELDS=NONE (which eliminates duplicates) as the header record only contains alphanumeric characters.

How do I achieve this?

Re: Merge Files

PostPosted: Mon Aug 02, 2010 9:50 pm
by MrSpock
A MERGE operation implies that you have n files of the same format, in sorted order on the same key, that you want to combine together into a single output file. Your description doesn't really seem to indicate that a MERGE is appropriate. Maybe you just want to concatenate 6 files into one?

Re: Merge Files

PostPosted: Mon Aug 02, 2010 9:53 pm
by skolusu
Gron,
The following DFSORT JCL will give you the desired results. I assumed that the header record is identified by '#' in position 1 and your input is FB recfm and LRECL of 80

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD *                                             
#                                                           
D1 - 1                                                     
D1 - 2                                                     
D1 - 3                                                     
//         DD *                                             
#                                                           
D2 - 1                                                     
D2 - 2                                                     
//         DD *                                             
#                                                           
D3 - 1                                                     
D3 - 2                                                     
D3 - 3                                                     
//         DD *                                             
#                                                           
D4 - 1                                                     
D4 - 2                                                     
D4 - 3                                                     
//         DD *                                             
#                                                           
D5 - 1                                                     
D5 - 2                                                     
D5 - 3                                                     
//         DD *                                             
#                                                           
D6 - 1                                                     
D6 - 2                                                     
D6 - 3                                                     
//SORTOUT  DD SYSOUT=*                                     
//SYSIN    DD *                                             
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:C'1',SEQNUM,8,ZD)),   
  IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),OVERLAY=(81:9C'0'))         
  SORT FIELDS=(81,9,CH,A),EQUALS                           
  SUM FIELDS=NONE                                           
  OUTREC BUILD=(1,80)                                       
//*


The output from the above is
#             
D1 - 1         
D1 - 2         
D1 - 3         
D2 - 1         
D2 - 2         
D3 - 1         
D3 - 2         
D3 - 3         
D4 - 1         
D4 - 2         
D4 - 3         
D5 - 1         
D5 - 2         
D5 - 3         
D6 - 1         
D6 - 2         
D6 - 3