z/OS DFSORT Application Programming Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 2 - Combine complete records from four files

z/OS DFSORT Application Programming Guide
SC23-6878-00

This example shows how you can use the WITHEACH operand to splice complete records from four different data sets together.

//S2    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//FILE1 DD DSN=...  input file1 - 300-byte records
//FILE2 DD DSN=...  input file2 - 400-byte records
//FILE3 DD DSN=...  input file3 - 150-byte records
//FILE4 DD DSN=...  input file4 -  20-byte records
//** BE SURE TO USE MOD FOR T1
//T1 DD DSN=&&TX,UNIT=SYSDA,SPACE=(CYL,(5,5)),
// DISP=(MOD,PASS)
//ALLRCDS DD DSN=...  output file - 870-byte records
//TOOLIN DD *
* Reformat the File1 records for splicing on added sequence number
  COPY FROM(FILE1) TO(T1) USING(CTL1)
* Reformat the File2 records for splicing on added sequence number
  COPY FROM(FILE2) TO(T1) USING(CTL2)
* Reformat the File3 records for splicing on added sequence number
  COPY FROM(FILE3) TO(T1) USING(CTL3)
* Reformat the File4 records for splicing on added sequence number
  COPY FROM(FILE4) TO(T1) USING(CTL4)
* Splice record-by-record on added sequence number
  SPLICE FROM(T1) TO(ALLRCDS) ON(871,8,PD) WITHEACH -
   WITH(301,400) WITH(701,150) WITH(851,20) -
   USING(CTL5)
/*
//CTL1CNTL DD *
* Reformat records to:
* 1          301        701        851        871
* File1bytes|400 blanks|150 blanks|20 blanks |seqno
  OUTREC FIELDS=(1,300,871:SEQNUM,8,PD)
/*
//CTL2CNTL DD *
* Reformat records to:
* 1          301        701        851        871
* 300 blanks|File2bytes|150 blanks|20 blanks |seqno
  OUTREC FIELDS=(301:1,400,871:SEQNUM,8,PD)
/*
//CTL3CNTL DD *
* Reformat records to:
* 1          301        701        851        871
* 300 blanks|400 blanks|File3bytes|20 blanks |seqno
  OUTREC FIELDS=(701:1,150,871:SEQNUM,8,PD)
/*
//CTL4CNTL DD *
* Reformat records to:
* 1          301        701        851        871
* 300 blanks|400 blanks|150 blanks|File4bytes|seqno
  OUTREC FIELDS=(851:1,20,871:SEQNUM,8,PD)
/*
//CTL5CNTL DD *
* Remove added sequence number from spliced records to get:
* File1bytes|File2bytes|File3bytes|File4bytes
 OUTFIL FNAMES=ALLRCDS,OUTREC=(1,870)
/*                                                                 
Because the data sets do not have a common key, we add sequence numbers to the records from each data set and use the sequence numbers as the ON field for SPLICE. Using this technique, we can splice together the 300-byte records from FILE1, the 400-byte records from FILE2, the 150-byte records from FILE3 and the 20-byte records from FILE4, to produce 870-byte records in ALLRCDS. Conceptually, the 870-byte records in ALLRCDS would look like this:
File1 Record1 ... File2Record1 ... File3Record1 ... File4Record1 ...
File1 Record2 ... File2Record2 ... File3Record2 ... File4Record2 ...
...

The base records originate from the FILE1 data set and the overlay records originate from the FILE2, FILE3 and FILE4 data sets.

Here is what the various ICETOOL operators do in this job:

The first COPY operator creates reformatted records in the T1 data set with the FILE1 records in positions 1-300, blanks in all other positions up to 870, and a sequence number in positions 871-878. The sequence number will be 1 for the first FILE1 record, 2 for the second FILE1 record, and so on.

The second COPY operator creates reformatted records in the T1 data set with the FILE2 records in positions 301-700, blanks in all other positions up to 870, and a sequence number in positions 871-878. The sequence number will be 1 for the first FILE2 record, 2 for the second FILE2 record, and so on.

The third COPY operator creates reformatted records in the T1 data set with the FILE3 records in positions 701-850, blanks in all other positions up to 870, and a sequence number in positions 871-878. The sequence number will be 1 for the first FILE3 record, 2 for the second FILE3 record, and so on.

The fourth COPY operator creates reformatted records in the T1 data set with the FILE4 records in positions 851-870, blanks in all other positions up to 850, and a sequence number in positions 871-878. The sequence number will be 1 for the first FILE4 record, 2 for the second FILE4 record, and so on.

Note that MOD is used for the T1 data set, so the reformatted records from FILE1, FILE2, FILE3 and FILE4 will be output in that order in T1, ensuring that they are sorted and spliced in that order.

The SPLICE operator sorts the records from T1 using the sequence number as the ON field. With WITHEACH, the reformatted FILE1 records are treated as the base records, and the reformatted FILE2, FILE3 and FILE4 records are treated as the overlay records; each WITH field is associated with an overlay record in turn. So the first WITH field specifies the bytes to be used from the second duplicate (FILE2 record), the second WITH field specifies the bytes to be used from the third duplicate (FILE3 record) and the third WITH field specifies the bytes to be used from the fourth duplicate (FILE4 record).

SPLICE matches each base and overlay record by their sequence numbers, and creates a new combined 878-byte record. The OUTFIL statement in CTL5CNTL is used to remove the sequence number so that the 870-byte spliced record is written to the ALLRCDS data set.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014