MainframeMaster

RDW Structure

The RDW (Record Descriptor Word) is a 4-byte prefix at the beginning of every variable-length record in z/OS. It tells the system how long that record is so it knows how many bytes to read. The length stored in the RDW is the total length of the record—including the 4-byte RDW itself. So a record with 80 bytes of data has an RDW that contains the value 84 (4 + 80). In DFSORT, when you specify positions in control statements (SORT FIELDS, INREC, OUTREC, INCLUDE, OMIT), those positions refer to the data portion of the record: position 1 is the first byte after the RDW. DFSORT maintains the RDW when reading and writing variable-length records; you do not normally build or modify it in control statements. This page explains the RDW layout, how the length is stored, how it differs from the BDW (Block Descriptor Word), and how DFSORT uses it.

Data Types & Formats
Progress0 of 0 lessons

What Is the RDW?

The Record Descriptor Word (RDW) is a 4-byte field that precedes the data of each variable-length record. It is used by the access method (e.g. QSAM, VSAM) and by utilities like DFSORT to determine how many bytes belong to that record. Without the RDW, the system would not know where one variable-length record ends and the next begins. So the layout of a variable-length record is: [RDW 4 bytes][data N bytes], and the value in the RDW equals 4 + N (the total length).

RDW Byte Layout

The exact format of the 4-byte RDW can be platform- and access-method-specific. A common layout is:

Typical RDW layout (common form)
BytesContent
1–2Record length (binary, typically big-endian), including the 4-byte RDW
3–4Reserved (often binary zeros or low-values)

So for a record with 80 bytes of data, the total length is 84. In hexadecimal, 84 is 0x54. In big-endian, the first 2 bytes might be X'0054' (00*256 + 84 = 84). The system reads the RDW, gets 84, and then reads 84 bytes total for that record (including the RDW); the remaining 80 bytes are the data. Your program or DFSORT then treats "position 1" as the first of those 80 data bytes.

Length Includes the RDW

The length stored in the RDW is always the total length of the record, including the 4-byte RDW itself. So:

  • Data length 0 → total 4 (RDW only).
  • Data length 80 → total 84.
  • Data length 252 → total 256 (common max data when LRECL=256).

This convention lets the system read the RDW (4 bytes), interpret the length, and then read the rest of the record (length − 4 bytes of data) in one consistent way.

How DFSORT Uses the RDW

When DFSORT reads variable-length records from SORTIN, it reads the RDW and the data as one logical record. It uses the RDW to know how many bytes to read. When it writes to SORTOUT (if the output is VB), it writes the RDW and then the data. The RDW is not included in the position numbers you specify in control statements. So when you code:

text
1
SORT FIELDS=(1,20,CH,A)

position 1 is the first byte of the data (the byte after the RDW). DFSORT automatically skips the RDW when applying SORT FIELDS, INREC, OUTREC, INCLUDE, and OMIT. You never have to say "position 5" to get the first data byte; position 1 is always the first data byte for variable-length records.

RDW vs BDW

In variable blocked (VB) datasets, there are two descriptor words:

RDW vs BDW
TermMeaning
RDWRecord Descriptor Word: 4 bytes at the start of each logical record; contains the record length (including RDW).
BDWBlock Descriptor Word: 4 bytes at the start of each physical block; contains the block length. A block can contain many records.

So a physical block might look like: [BDW][RDW+data][RDW+data][RDW+data].... The BDW tells how long the whole block is; each RDW tells how long that record is. DFSORT works with logical records (RDW + data); the blocking (BDW) is handled by the access method.

Do You Modify the RDW in DFSORT?

Normally no. When you use INREC or OUTREC, you specify positions and build the data portion. DFSORT (and the access method) take care of generating or preserving the RDW when writing variable-length output. If you build a 60-byte data record and write it to a VB dataset, the product will typically write a 4-byte RDW containing 64 followed by your 60 bytes. For special cases (e.g. building the RDW explicitly), behavior is product-dependent—see your DFSORT manual.

Fixed-Length Records Have No RDW

Fixed-length (FB) records do not have an RDW. Each record is exactly LRECL bytes; the system knows the length from the DCB. So for FB, position 1 is simply the first byte of the record. The RDW exists only for variable-length (V or VB) records.

Explain It Like I'm Five

Imagine each variable-length "paper" has a tiny sticker at the very top that says "This paper is 84 lines long." That sticker is the RDW. The computer reads the sticker first, sees 84, and then reads 84 lines (including the sticker). So it knows exactly where that paper ends and the next one begins. When we talk about "line 1" of the paper, we mean the first line of the actual content, not the sticker. The sort program uses the sticker to read the right amount, but when we say "sort by the first 10 lines," we mean the first 10 lines of the content—that's why position 1 is after the RDW.

Exercises

  1. A variable-length record has 100 bytes of data. What is the total record length (decimal)? What might the first 2 bytes of the RDW contain (hex) for that length in big-endian?
  2. In DFSORT, for a VB record with 50 bytes of data, does SORT FIELDS=(1,10,CH,A) reference the RDW or the data? Explain.
  3. What is the difference between the RDW and the BDW? Which one is per record and which is per block?
  4. Why does the length in the RDW include the 4-byte RDW itself?

Quiz

Test Your Knowledge

1. How many bytes is the RDW?

  • 2 bytes
  • 4 bytes
  • 8 bytes
  • Variable

2. What does the length in the RDW include?

  • Only the data bytes
  • Only the first 2 bytes of the RDW
  • The entire record length including the 4-byte RDW itself
  • The block length

3. In DFSORT control statements, do you reference the RDW bytes as position 1–4?

  • Yes; position 1 is the first byte of the RDW
  • No; positions refer to the data portion—position 1 is the first byte after the RDW
  • Only in INREC
  • Only for MERGE

4. What is the BDW in a VB block?

  • Same as RDW
  • Block Descriptor Word: a 4-byte prefix at the start of each block containing the block length
  • A sort key
  • Only used in DFSORT

5. If a variable-length record has 100 bytes of data, what value (decimal) would typically be in the RDW length field?

  • 100
  • 104 (4 for RDW + 100 for data)
  • 96
  • 0