Merging previously sorted data sets

You can use DFSORT's MERGE operator to create merged output data sets. A single MERGE operator can be used to merge up to 50 input data sets which were previously sorted by the same fields in the same locations. MERGE can create one output data set or up to 10 identical output data sets. Using INCLUDE or OMIT statements, you can select a subset of the input records. Using INREC or OUTREC statements, you can rearrange the fields of the input records. Using OUTFIL statements, you can create any number of output data sets with different subsets of records or arrangements of fields.

You can use up to 10 FROM operands to specify up to 50 input data sets. You must specify a USING data set to specify a DFSORT MERGE statement that tells MERGE the fields your input data sets are already sorted on. You can use various other DFSORT statements as well; see z/OS DFSORT Application Programming Guide for details.

Suppose you have two input data sets previously sorted by Branch Number as follows:

Input file1
0003 Sacramento
0005 Palo Alto
0008 Morgan Hill
Input file2
0002 Los Angeles
0006 Modesto
0009 San Jose
The following JCL and ICETOOL statements would merge the two input data sets on the Branch Number:
//MRG EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DSN=INPUT.FILE1,DISP=SHR
//IN2 DD DSN=INPUT.FILE2,DISP=SHR
//OUT DD DSN=OUTPUT.FILE,DISP=(NEW,CATLG,DELETE),
//  UNIT=SYSDA,SPACE=(CYL,(5,5))
//TOOLIN DD *
   MERGE FROM(IN1,IN2) TO(OUT) USING(CTL1)
/*
//CTL1CNTL DD *
   MERGE FIELDS=(1,4,ZD,A)
/*
The output data set would have these merged records:
0002 Los Angeles    
0003 Sacramento     
0005 Palo Alto      
0006 Modesto        
0008 Morgan Hill    
0009 San Jose       
So far
So far in this chapter you have learned how to print statistics for numeric fields, create sorted and unsorted data sets, obtain a count of numeric fields in a range for a particular field, print fields from an input data set, print reports, print a count of field occurrences, select output records based on field occurrences, join fields from different data sets, match records from different data sets, sort records between headers and trailers, keep or remove headers, trailers or relative records, and merge previously sorted data sets. The last part of this chapter shows the complete main ICETOOL job and its resulting TOOLMSG output.