How to use Variable Block (VB) Records in DFSORT with Record Descriptor Word (RDW)

This tutorial will focus on variable block (VB) datasets/records and how to consider the record descriptor word (RDW) while sorting using DFSORT.

Fixed block (FB) records/datasets always starts from position 1. Thus sorting a FB dataset is fairly easy as we know from which positions the records and its various fields starts and where it ends. The situation is bit different for Variable Block (FB) records.

VB Record Organization

In VB records, 1st 4 bytes are named as Record Descriptor Word (RDW). In this 4 bytes, 1st two bytes contains the length of the records including the length RDW itself and it is binary half-word i.e. PIC S9(4) COMP. The last two bytes contains LOW-VALUES (x’0000′) and it is reserved for future use.

VB Record and SORT Control Options

While writing SORT control statements for a VB record, one must consider this 4 bytes while coding. For example:


If your actual records starts from position 1 to 14, you should write the SORT statements as above, adding 4 bytes of RDW.

Handling Missing Control Fields in a VB record using VLSHRT

Variable records can vary in any size and there is a chance that any of the VB record may not have any value in the positions that you specified in the SORT statements. If this happens, DFSORT will immediately terminate. For example:


In the above example, the control fields is in position 20-34. If the fixed part and variable part of the records falls inside the control range and if the actual variable record length is less than 34, then they would be missing some bytes at the end of the control record.

In this situation the SORT option VLSHRT should be used to prevent abnormally termination of SORT program.


SORT will automatically replace missing bytes of control records with binary ZEROes if the option VLSHRT is used.

In contrast, there is another option NOVLSHRT which behaves exactly opposite of VLSHRT. If NOVLSHRT is used, SORT terminates if a sort control field is found in VB record.

Filed under: