In DFSORT, fixed-length records are records where every record has the same length. The dataset is typically defined with RECFM=FB (Fixed Block) or RECFM=F (Fixed). There is no RDW (Record Descriptor Word); each record is exactly LRECL (logical record length) bytes. Position 1 in control statements is the first byte of the record, position 2 the second, and so on. Fixed-length is the most common format for traditional mainframe files: 80-byte card images, fixed-format reports, and input/output for programs that expect a constant record size. This page explains how fixed-length records work with DFSORT, how to set LRECL on SORTIN and SORTOUT, how position numbering works, and when to use fixed-length versus variable-length.
A fixed-length record is one where every record in the dataset has the same number of bytes. That length is called the logical record length (LRECL). For example, if LRECL=80, every record is exactly 80 bytes. There is no prefix (no RDW); the first byte of the record is the first data byte. The system knows how long each record is from the dataset's DCB (Data Control Block), so it can read one record after another without a length field in each record.
RECFM=FB means Fixed Block: fixed-length records, blocked (multiple records per physical block). RECFM=F means Fixed, unblocked (one record per block; less common). For DFSORT, you typically use RECFM=FB and LRECL=n when allocating SORTIN and SORTOUT for fixed-length data. The "B" allows efficient I/O by grouping records into blocks.
For fixed-length records, position 1 is the first byte of the record, position 2 is the second byte, and so on up to position LRECL. So:
1SORT FIELDS=(1,10,CH,A,11,4,PD,D)
sorts by the first 10 bytes (character ascending), then by bytes 11–14 (packed decimal descending). All positions refer to the same 1-based byte positions in each record. There is no offset for an RDW because fixed-length records do not have one.
For fixed-length input, allocate SORTIN with RECFM=FB and LRECL equal to the length of each input record. For fixed-length output, allocate SORTOUT with RECFM=FB and LRECL equal to the length of each output record. If you use INREC to shorten or lengthen the record, the record seen by the sort phase has the new length; if you use OUTREC to build the final record, the length of that built record must match SORTOUT's LRECL. So:
| Aspect | Fixed (FB) | Variable (VB) |
|---|---|---|
| Record length | Same for every record (LRECL) | Varies; max = LRECL (incl. 4-byte RDW) |
| RDW | None | 4-byte prefix per record |
| Position 1 | First byte of record | First byte of data (after RDW) |
| When to use | Same layout/length; legacy fixed format | Variable-length data; save space |
When DFSORT cannot infer the record format from the DD or dataset (e.g. tape or dynamic allocation without DCB), use the RECORD statement:
1RECORD TYPE=F,LENGTH=80
TYPE=F indicates fixed-length. LENGTH=80 is the logical record length in bytes. For normal disk datasets with DCB=(RECFM=FB,LRECL=80), RECORD is usually not needed.
Use variable-length (VB) when records naturally vary in length (e.g. free-text, variable-length comments) and you want to avoid padding short records to a fixed size. VB uses an RDW and saves space when many records are shorter than the maximum.
Imagine a stack of index cards where every card has exactly 80 spaces—no more, no less. When we look at "position 1," we mean the first space on the card. We don't need a label saying how long the card is because every card is the same length. That's fixed-length. The sort program reads one card (80 bytes), then the next 80 bytes, and so on. When we write the sorted cards to the outbox, each card we write is also 80 spaces. So the inbox and outbox are both made for 80-space cards.
1. What does FB mean in RECFM=FB?
2. For a fixed-length dataset with LRECL=80, what is position 1 in SORT FIELDS?
3. Why might you choose fixed-length (FB) over variable-length (VB) for a sort output?
4. If you use OUTREC to build a 60-byte record from an 80-byte input, what LRECL should SORTOUT have?
5. Do fixed-length records have an RDW?