Variable length records - wrong length READ
Originally, Enterprise COBOL V5.1 changed
the behavior for wrong length READ compared to previous COBOL compilers;
but for Enterprise COBOL V5.1 with current
service applied, V5.2, and later versions, that behavior can
be changed via a new compiler option, VLR(COMPAT|STANDARD)
that
was introduced to control whether you get the original standard-conforming
behavior of COBOL V5.1 without service applied, or the behavior that
is compatible with earlier COBOL compilers. It eases your migration
from earlier versions to Enterprise COBOL V5 and V6, if your programs
have READ
statements that result in a record length
conflict.
The 85 COBOL standard specifies the following
rules as part of the processing of READ
statements: If
the number of character positions in the record that is read is less
than the minimum size specified by the record description entries
for the file, the portion of the record area which is to the right
of the last valid character read is undefined. If the number of character
positions in the record that is read is greater than the maximum size
specified by the record description entries for file-name-1, the record
is truncated on the right to the maximum size. In either of these
cases, the READ statement is successful and an I-O status value of
04 is set indicating that a record length conflict has occurred.
04
when READ
statements
encountered a record length conflict. However, if your programs are
compiled with one of the following compilers, you get the status value
of 00
, which is the nonstandard result for READ
statements.- VS COBOL II V1.3 with PTFs for APAR PN34704 installed
- VS COBOL II V1.4 with PTFs for APAR PN38730 installed
- COBOL/370 V1.1 or V1.2 with PTFs for APAR PN36445 installed
- COBOL for OS/390® & VM, V2
- Enterprise COBOL V3 or V4
VLR(COMPAT)
compiler option.If you specify
VLR(COMPAT)
, you getFile Status 00
whenREAD
statements encounter a record length conflict orwrong length READ
.If your program performs a
wrong length READ
and your code checks forFile Status=0
after reading variable-length record files, your code will take the "zero" path, just as it did in Enterprise COBOL V4 and earlier versions.Note: This setting can hide I/O problems that can arise with the wrong length READ situation. Use theVLR(COMPAT)
option with caution, and check for correctREAD
statements.If you specify
VLR(STANDARD)
, you getFile Status 04
whenREAD
statements encounter a record length conflict orwrong length READ
. Using this setting, you can check forFS=04
and then add code to avoid accessing undefined data in a record and also avoid getting protection exceptions for attempting to reference a part of the record that was truncated.If your program performs a
wrong length READ
and your code checks forFile Status=0
after reading variable-length record files, your code will take the "Not zero" path. You can change your code to test forFS=0
, whileFS=4
and other values will all be a failedREAD
. ForFS=4
, you can add code to avoid the bad data in variables or protection exceptions.
Using VLR(STANDARD) can result in more reliable code and
fewer I/O problems because the file status will tell you when a wrong
length READ
might occur. A new compiler message, MSGIGYP3178,
can also help you avoid I/O problems by telling you if a program has
a possibility of a wrong length READ
. This message can be used
to assist with migration from VLR(COMPAT) to VLR(STANDARD) by indicating
the possible "wrong length READ" that you can solve by correcting
the File Definition (FD). You can also raise the severity of the message
so that the program must be corrected in order to run. To do this,
use the MSGEXIT suboption of the EXIT compiler option to change the
severity of message MSGIGYP3178 from I (RC=0) to S (RC=12), E (RC=8),
or W (RC=4). If you are not interested in seeing this message, you
can suppress the message completely.