Mainframe (z/OS)

Sort and filter a file with DFSORT

Sort records, keep only the ones you want or remove duplicates in a batch job.

z/OS
Fill these in once
  1. Sort by the first 10 characters
    Inside JCL
    //SORT     EXEC PGM=SORT
    //SYSOUT   DD SYSOUT=*
    //SORTIN   DD DSN=MYUSER.INPUT,DISP=SHR
    //SORTOUT  DD DSN=MYUSER.SORTED,DISP=(NEW,CATLG,DELETE),
    //            SPACE=(CYL,(1,1)),UNIT=SYSDA,DCB=*.SORTIN
    //SYSIN    DD *
      SORT FIELDS=(1,10,CH,A)
    /*

    1,10 means start at column 1, 10 characters long. A is ascending, D descending.

  2. Keep only some records (replace the SYSIN lines)
    Inside JCL
    INCLUDE COND=(11,2,CH,EQ,C'NY')
    SORT FIELDS=COPY

    Keeps records with NY in columns 11 and 12, without sorting.

  3. Remove duplicate records (replace the SYSIN lines)
    Inside JCL
    SORT FIELDS=(1,10,CH,A)
    SUM FIELDS=NONE

    Keeps one record for each key in columns 1 to 10.