MainframeMaster

Fixed-Length Records

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.

Data Types & Formats
Progress0 of 0 lessons

What Is a Fixed-Length Record?

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 and RECFM=F

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.

Position Numbering

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:

text
1
SORT 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.

LRECL on SORTIN and SORTOUT

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:

  • Input 80 bytes, no INREC/OUTREC → SORTIN LRECL=80, SORTOUT LRECL=80.
  • Input 80 bytes, OUTREC builds 60 bytes → SORTOUT LRECL=60.
  • Input 80 bytes, INREC builds 50 bytes for sort, OUTREC builds 60 for output → SORTOUT LRECL=60 (the sort works on 50-byte records; output is 60).

Fixed vs Variable: Comparison

Fixed vs variable length
AspectFixed (FB)Variable (VB)
Record lengthSame for every record (LRECL)Varies; max = LRECL (incl. 4-byte RDW)
RDWNone4-byte prefix per record
Position 1First byte of recordFirst byte of data (after RDW)
When to useSame layout/length; legacy fixed formatVariable-length data; save space

RECORD Statement for Fixed-Length

When DFSORT cannot infer the record format from the DD or dataset (e.g. tape or dynamic allocation without DCB), use the RECORD statement:

text
1
RECORD 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.

When to Use Fixed-Length

  • Downstream programs or reports expect a constant record length (e.g. 80-byte lines).
  • All logical records have the same layout and length; no need for variable length.
  • Legacy file formats (card image, fixed-format tape) are fixed-length.
  • You want simple, predictable positioning: byte 1 is always the first byte of the record.

When to Use Variable-Length Instead

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.

Explain It Like I'm Five

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.

Exercises

  1. Your input has LRECL=100. You use OUTREC to build a 70-byte record. What LRECL should you use for SORTOUT?
  2. What is the difference between RECFM=F and RECFM=FB? Which do you typically use for DFSORT?
  3. For a fixed-length 80-byte record, does position 80 refer to the last byte of the record? What about position 81?
  4. When would you code RECORD TYPE=F,LENGTH=80 in SYSIN?

Quiz

Test Your Knowledge

1. What does FB mean in RECFM=FB?

  • File binary
  • Fixed Block: all records have the same length
  • Full block
  • Format byte

2. For a fixed-length dataset with LRECL=80, what is position 1 in SORT FIELDS?

  • The 80th byte
  • The first byte of the record (byte 1 of 80)
  • The block header
  • Position 1 is only for VB

3. Why might you choose fixed-length (FB) over variable-length (VB) for a sort output?

  • FB is always faster
  • When downstream programs or legacy systems expect a fixed record length (e.g. 80 bytes); or when every logical record is the same size and padding is acceptable
  • VB is never used with DFSORT
  • Only when using MERGE

4. If you use OUTREC to build a 60-byte record from an 80-byte input, what LRECL should SORTOUT have?

  • 80
  • 60 (match the output record length)
  • Any value
  • 120

5. Do fixed-length records have an RDW?

  • Yes, a 4-byte RDW
  • No; fixed-length records have no RDW; each record is exactly LRECL bytes
  • Only when RECFM=FBS
  • Only for SORTIN