DATASORT operator

Read syntax diagramSkip visual syntax diagram
>>-DATASORT--FROM(indd)--TO(outdd)--USING(xxxx)----------------->

>--+-HEADER----+--+-TRAILER----+--+-------------+--------------><
   +-FIRST-----+  +-LAST-------+  '-VSAMTYPE(x)-'   
   +-HEADER(u)-+  +-TRAILER(v)-+                    
   '-FIRST(u)--'  '-LAST(v)----'                    

Copies one or more header records and one or more trailer records to the output data set in their original input record order, while sorting the data records between the header and trailer records, using the DFSORT control statements in xxxxCNTL. By definition, the header records are the first n records in the input data set, the trailer records are the last n records in the input data set, and the data records (also called detail records) are the records between the header and trailer records. Thus, the first n records (header records) and last n records (trailer records) are kept in place and the data records between them are sorted.

You must specify one header operand (HEADER, FIRST, HEADER(u) or FIRST(u)), one trailer operand (TRAILER, LAST, TRAILER(v) or LAST(v)), or one header operand and one trailer operand. If you specify a header operand without a trailer operand, only the header records will be kept in place. If you specify a trailer operand without a header operand, only the trailer records will be kept in place. If you specify a header operand and a trailer operand, both the header records and trailer records will be kept in place.

DFSORT is called to copy the header and trailer records and to sort the data records. DFSORT uses its E15 and E35 exits to process the records as needed. ICETOOL passes the EQUALS option to DFSORT to ensure that duplicates are kept in their original input order.

You must supply a DFSORT SORT statement in the xxxxCNTL data set to indicate the control fields for sorting the data records.

You can use additional DFSORT control statements in xxxxCNTL providing you observe these rules:
  • A SORT statement must be present
  • MODS and OUTREC statements should not be present.
  • A STOPAFT operand should not be present.
  • Comment statements can be present.
  • Header and trailer records will only be affected by the SKIPREC option and OUTFIL statements. SKIPREC=n will remove the first n indd records, so the first header record will be the n+1 indd record. OUTFIL statements will process the header and trailer records in the normal way.
  • Data records will be processed by INCLUDE, OMIT, INREC, SUM, OPTION and OUTFIL statements in the normal way.
  • If you use INREC to change the length of the data records, DFSORT will preserve the header and trailer records by setting the TO data set LRECL to the maximum of the input or reformatted record length. For fixed-length records, DFSORT will pad the header and trailer records, or data records, on the right with blanks as appropriate.
  • You can further process the outdd records after DATASORT processing using an OUTFIL statement like this:
      OUTFIL FNAMES=outdd,...
    or multiple OUTFIL statements like this:
      OUTFIL FNAMES=outdd,...
      OUTFIL FNAMES=outdd1,...
    For example, with TO(OUT1) you could further modify the OUT1 records after DATASORT processing, with a statement like this:
      OUTFIL FNAMES=OUT1,REMOVECC,
        TRAILER1=('Record count ',COUNT=(M11,LENGTH=5))

ICETOOL requires extra storage for DATASORT processing, over and above what is normally needed by ICETOOL and DFSORT, in order to save your header and trailer records. The amount of storage needed depends on the number of header and trailer records you specify, and the LRECL of the FROM data set. In most cases, the needed storage can be obtained (above 16MB virtual). However, if ICETOOL cannot get the storage it needs, it issues a message and terminates the DATASORT operation. Increasing the REGION by the amount indicated in the message may allow ICETOOL to run successfully.

The DYNALLOC option is passed to DFSORT to ensure that work space is available for the sort. If your installation defaults for dynamic allocation are inappropriate for a DATASORT operator, you can take one of the following actions:
  1. Override the DYNALLOC option using an OPTION control statement such as:
      OPTION DYNALLOC=(,8)

    in the xxxxCNTL data set.

  2. Use xxxxWKdd DD statements to override the use of dynamic allocation. Refer to SORTWKdd DD statement for details.

Tape work data sets cannot be used with ICETOOL.