THE SHORT ANSWER
In a variable-length file each record starts with a 4-byte record descriptor word (RDW), and each block starts with a 4-byte block descriptor word (BDW). Both start with a 2-byte length that includes the 4 bytes of the word itself.
Steps
- Read the RDW. The first 2 bytes of a record hold its length, including the 4-byte RDW (4 to 32,760). The third and fourth bytes are zero (other values are used for spanned records).
- Find the next record. Add the RDW length to the position of the record to land on the next RDW.
- Read the BDW. A non-extended BDW has bit 0 zero, bits 1 to 15 the block length (8 to 32,760, counting the BDW and all records), and bits 16 to 31 zero.
- Count positions from the RDW. In DFSORT the first data byte of a variable-length record is position 5, because the first 4 bytes are the RDW.
- Check what your file really has. A file may keep the BDW and RDW, keep only the RDW, or have neither. The tool below looks at the bytes and tells you.
Worked example: two records in one block
Records ABC and HELLO in EBCDIC, with their descriptor words:
0014 0000 | 0007 0000 C1C2C3 | 0009 0000 C8C5D3D3D6
BDW 0014 0000 block length 20 = 4 + 7 + 9
RDW 0007 0000 record length 7 = 4 + 3 data bytes (ABC)
RDW 0009 0000 record length 9 = 4 + 5 data bytes (HELLO)Kit's file health check reads this as format VB (20 bytes) with 2 records: C1C2C3 = ABC and C8C5D3D3D6 = HELLO.
Related: Record decoder · Block size calculator · S0C7 data exception · Learn the basics on Mainframe Path
Sources, checked : Record descriptor word (RDW), z/OS 3.2.0 DFSMS Using Data Sets; Block descriptor word (BDW), z/OS 3.2.0 DFSMS Using Data Sets; SORT control statement, z/OS 3.2.0 DFSORT. Explanations are in our own words; the worked example is invented. Confirm against IBM documentation before changing production systems. mainframekit.com/guides/rdw-and-bdw-explained/