Datasets and Rules


The files used in SORT for processing and its DDnames, coding rules are provided below -

----+----1----+----2----+----3----+----4----+----5---+
//job-card
//*
//STEP10   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.DFSORT.INPUT,DISP=SHR
//SORTOUT  DD DSN=MATEPK.DFSORT.OUTPUT,...
//SORTWKnn DD SPACE=(CYL,(1,1),RLSE),UNIT=SYSDA 
//SYSIN    DD *
   control-statements
/*
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SYSDUMP  DD SYSOUT=*

Input files - SORTIN and SORTINnn


DFSORT input file referred with the DDname SORTIN. The input files can be coded in two scenrios -

  1. Input for Sorting or Copying These files are coded with SORTIN DD statement.
  2. Input for Merging. These files specifed with SORTINnn DD statement.

If SORTIN DD statement is coded, then it specifies that Sorting or Copying process in effect by default. If SORTINnn DD statements is coded, then it specifies that Merge process in effect by default. In SORTINnn, nn can be from 00 to 99. i.e, At max 100 files can be used in Merge process.

Points to Note -

For Copying or Sorting process, avoid using the same file name for SORTIN and SORTOUT to restrict unpredictable results. For Sort process, the SORTIN data set should not be the same as any SORTWKnn file.

Output files - SORTOUT and OUTFIL


Output files are used to store the DFSORT processed data (output). DFSORT output referred with DDname SORTOUT if no OUTFIL is coded. If OUTFIL is coded, then the final output will be stored in the DDnames coded with OUTFIL files. The output files can code in three ways -

  1. Single output file with SORTOUT and no OUTFIL.
  2. Single output file with OUTFIL.
  3. Multiple output files with OUTFIL.

Rules to Remember -

SORTOUT DD statement is coded to generate single non-split output file during process. The FNAMES and FILES parameters of one/more OUTFIL statements are used to specifiy the DDnames of the OUTFIL files. The OUTFIL statement parameters defines its processing to be performed on the OUTFIL files associated with that DDname. Each DDname coded in OUTFIL statement should have a corresponding DD statement.

WORK files - SORTWKnn


The SORTWKnn files are used as temporary storage areas for DFSORT records processing. Upto 255 SORTWK files can be coded for intermediate process. SORTWKnn files can be on DISK or on TAPE, but not both. nn value can be a combination of numeric and alphabets. One or more SORTWKnn files are required for sorting process (not for merge or copy), unless:

  • Input in main storage.
  • Dynamic work space allocation has been requested (DYNALLOC).

In SORTWKdd, it wont treat the DD names are duplicate until two DD names are exactly equal. If SORTWKdd used DISK as temporary storage and DFSORT terminates unsuccessfully, the temporary storage will also get released.

Rules to Remember -

  1. Input files can be blocked or unblocked QSAM or VSAM file if using for Sorting or Copying.
  2. The files can contain fixed or variable-length records.
  3. Input files can be concatenated even if they are on different devices.
  4. If OUTFIL used, an output file must be the same type (fixed or variable) as input file.

The maximum record length DFSORT can handle based on the type of the files like below -

  • Record length coded should not exceed the maximum record length.
  • Fixed-length records are limited to 32760 bytes.
  • Variable-length records are limited to 32756 bytes and for VSAM, it is 32752 bytes.
  • Variable block-spanned records are limited to 32767 bytes.
  • For tape work file sorting, the maximum record length is limited to 32752 bytes with NOEQUALS in effect and to 32748 bytes with EQUALS in effect.