Datalength

Datalength specifies the maximum number of bytes to be read. The value must be less than or equal to the size of buffer in bytes.

To avoid a truncation warning, datalength must be specified, for fixed-length records, as the product of the number of records to be read and the logical record length (lrecl):
  • datalength=records x lrecl
However, it is not considered an error if datalength is not equal to this product. When it is not, it is possible to skip data in the file during sequential reads. For example, suppose a file has twenty 80-byte, fixed-length records. If the first read from the file requests five records (5 x 80 = 400) and specifies a datalength of 300, the data from the first three records (3 x 80 = 240) and the first 60 bytes of the fourth record are placed in the buffer (240 + 60 = 300), and a truncation warning is returned (return code = 4). If the next read does not specify a position number, reading begins with record six, thereby skipping the last 20 bytes in record four and all of record five.
For variable-length records, the datalength is equal to the maximum logical record length, or
  • datalength = 1 x lrecl