MainframeMaster

DFSORT helper

Build INCLUDE, OMIT, SORT FIELDS, and OUTREC BUILD from start, length, and format. Or paste cards you already have and read them in English. The sample job uses PGM=SORT, SORTIN, SORTOUT, SYSOUT, and SYSIN.

How to use it

  1. Build mode: set the filter, the sort key, and the OUTREC pieces you want in the output record.
  2. Positions start at 1. On a VB record, bytes 1 through 4 are the RDW, so the first data byte is 5.
  3. Explain mode: paste SYSIN. A comma at the end of a line continues the statement. A line that starts with * is a comment.

Runs in your browser. Nothing is uploaded.

DFSORT helper

//SORTSTEP JOB (ACCT),'DFSORT',CLASS=A,MSGCLASS=X
//*
//* Change CLASS, MSGCLASS, and the dataset names for your shop.
//* PGM=SORT is the usual alias. PGM=ICEMAN calls DFSORT directly.
//*
//STEP010  EXEC PGM=SORT
//SORTIN   DD DISP=SHR,DSN=USER.SORT.INPUT
//SORTOUT  DD DISP=(NEW,CATLG,DELETE),
//            DSN=USER.SORT.OUTPUT,
//            SPACE=(CYL,(5,1)),UNIT=SYSDA
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
 INCLUDE COND=(15,2,CH,EQ,C'NY')
 SORT FIELDS=(1,10,CH,A)
 OUTREC BUILD=(1,10,2X,15,2)
/*

Need this at work?

Free account saves tutorial progress. The jobs board lists openings that ask for JCL.

DFSORT jobs on the board

When each statement runs

DFSORT reads SORTIN, optionally reformats with INREC, then applies INCLUDE and OMIT, then sorts (unless you coded COPY), then writes. OUTREC changes the record during that write. OUTFIL can filter and rebuild again for a DD of its own. A position in OUTREC is a position in the record that survived the sort, which is the SORTIN layout only when you did not use INREC.

  • INCLUDE keeps the record when COND= is true.
  • OMIT drops the record when COND= is true.
  • SORT FIELDS=(p,m,f,A) orders by that field, low to high. D is high to low. A second key is a tie-break.
  • SORT FIELDS=COPY and OPTION COPY leave the input order alone.
  • OUTREC BUILD lists the output bytes in order: a field (p,m), blanks (nX), or a C'constant'.

Formats

The format tells DFSORT how to compare or sort those bytes. The wrong format still runs. It just orders or filters on a different interpretation of the same storage.

  • CH: EBCDIC characters, one byte each. C'NY' must be the same length as the field.
  • ZD: zoned decimal, the COBOL DISPLAY form. One digit per byte, sign in the rightmost zone.
  • PD: packed decimal, the COBOL COMP-3 form. Two digits per byte, sign in the last nibble.
  • BI: unsigned binary.
  • FI: signed binary, two's complement. Typical lengths are 2, 4, and 8.

Date formats such as Y2C and DT1 are real DFSORT formats. Explain mode names them. The builder stays on CH, ZD, PD, BI, and FI. For TOJUL and TOGREG, use the DFSORT date conversion pages.

Sample the builder starts from

jcl
1
2
3
INCLUDE COND=(15,2,CH,EQ,C'NY') SORT FIELDS=(1,10,CH,A) OUTREC BUILD=(1,10,2X,15,2)

Keep records whose bytes 15 and 16 are NY. Sort the ten-byte character field at the front, ascending. Write those ten bytes, two blanks, then the state code.

What explain mode skips

IFTHEN, PARSE, FINDREP, OVERLAY, and edit masks (EDIT=, M4, and the like) show up as a short note, not a full reading. JOINKEYS, OUTFIL report headers, and most OPTION keywords beyond COPY, EQUALS, SKIPREC, STOPAFT, VLSHRT, DYNALLOC, and Y2PAST are in the same bucket. IBM documents the rest in the DFSORT Application Programming Guide.

Explain it like I'm 5

SORTIN is a stack of cards. INCLUDE is a helper who keeps only the cards you asked for. SORT is the helper who puts the remaining cards in order. OUTREC is the helper who copies just the bits you want onto a new card, with blank spaces where you asked for them.

FAQ

Related Pages

More detail

Field-by-field writeups live on the INCLUDE, OUTREC, and OUTFIL tutorials. Other calculators are on /tools.