Reading variable length records, information can be retained from the previous record.

Document ID : KB000053830
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

When variable length PDS records are read in by a program the field is not cleared of the content obtained in a previous read. If the present record is shorter than the previous record, the rest of the field contains information from the previous record.

Solution:

CA-Easytrieve doesn't "initialize" buffers, and didn't under 6.4 either. The rule is that buffers are never initialized and you should never use data in a variable file's buffer beyond the value contained in RECORD-LENGTH. The move is always done only for the value of RECORD-LENGTH which is why data from longer previous records is undisturbed.

This is done by design and CA-Easytrieve 6.4 worked the same way when told to use "move mode" by the use of the WORKAREA parameter.

Before r11.x, fields could be defined that exceeded the length of the file record.
With r11.x, if coded, the record length of the FILE is used to calculate the maximum length (starting position + length) of the fields defined for that file.
Formerly, field re-definitions could redefine any field without doing length comparisons.
With r11.x, a redefinition must point to an originating field with the proper length.

Whether we use locate or move mode, the rules are the same: never refer to data beyond RECORD-LENGTH as it doesn't belong to the record and it's value is unpredictable. The proper and safe way to use a buffer in a variable file where you cannot "guarantee" it will be there (such as a fixed portion of the record) is to move the data to a work area as in this
example:

FILE VFILE VB(20 0) 
REC 1 16 A 
JOB INPUT VFILE 
DEFINE MYWORKAREA S 16 A 
MOVE REC RECORD-LENGTH TO MYWORKAREA FILL ' ' 

That logic ensures that MYWORKAREA will always contain a safe 16 byte space filled field.