Example 2

 * Method 1
 SORT FROM(IN) TO(DEPT1) USING(DPT1)
 SORT FROM(IN) TO(DEPT2) USING(DPT2)
 SORT FROM(IN) TO(DEPT3) USING(DPT3)
 * Method 2
 SORT FROM(IN) USING(ALL3)
This example shows two different methods for creating sorted subsets of an input data set. Assume that:
  • The DPT1CNTL data set contains:
     SORT FIELDS=(51,2,BI,A,18,5,CH,A,58,4,BI,A)
     INCLUDE COND=(5,3,CH,EQ,C'D01')
  • The DPT2CNTL data set contains:
     SORT FIELDS=(51,2,BI,A,18,5,CH,A,58,4,BI,A)
     INCLUDE COND=(5,3,CH,EQ,C'D02')
  • The DPT3CNTL data set contains:
     SORT FIELDS=(51,2,BI,A,18,5,CH,A,58,4,BI,A)
     INCLUDE COND=(5,3,CH,EQ,C'D03')
  • The ALL3CNTL data set contains:
     SORT FIELDS=(51,2,BI,A,18,5,CH,A,58,4,BI,A)
     OUTFIL FNAMES=DEPT1,INCLUDE=(5,3,CH,EQ,C'D01')
     OUTFIL FNAMES=DEPT2,INCLUDE=(5,3,CH,EQ,C'D02')
     OUTFIL FNAMES=DEPT3,INCLUDE=(5,3,CH,EQ,C'D03')
Method 1 requires three calls to DFSORT and three passes over the input data set:
  • The first SORT operator sorts the records from the IN data set that contain D01 in positions 5-7 to the DEPT1 data set
  • The second COPY operator sorts the records from the IN data set that contain D02 in positions 5-7 to the DEPT2 data set
  • The third COPY operator sorts the records from the IN data set that contain D03 in positions 5-7 to the DEPT3 data set.

Method 2 accomplishes the same result as method 1 but, because it uses OUTFIL statements instead of TO operands, requires only one call to DFSORT and one pass over the input data set.