Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
You understand the concept of a fixed length record; all records in a file are of the same length and probable the same description.
In a variable length record the file can contain records of mixed lengths, and mixed descriptions. This can be because of many reasons. Maybe your looking at an unload of an IMS database. The file may contain the same results as if you were to progress through the database with a ?get next?. You would get an i.e. parent segment (lrecl 100), a child-1 segment (lrecl 75), a child-2 segment (lrecl 300), and so on until you get the next parent segment again.
Or say you have a record description something like this for every property in the state of California (all 200 million of them)
This could be a fixed length record, using 5111 bytes each, or, because the average LPD is only 125 characters you could make the dataset size MUCH smaller by making the record a variable length record, containing only the LPD required.
Now how do you read this in COBOL? There are a multitude of variations you can use, but the two I have used are:
WORKING STORAGE SECTION.
01 RECORD-LENGTH PIC S9(8) COMP.
When you read the V record, RECORD-LENGTH will be populated with the number of bytes what were read. From this you can calculate the number of characters in the LPD.
Disclaimer: I don?t use variable length records very much and usually have to play with the code a little before I remember exactly what the correct syntax is. But in general this is what V records are.
If you browse a variable length file, you will see an additional 4 bytes preceding each record. This is a 4 byte binary length of the block, and needs to be taken into consideration when sizing the block size for a new file. In COBOL this is taken care of and you don?t see it.
If this isn't what you are looking for, please come back.
Two points to add to David's excellent description:
The DEPENDING ON subject, RECORD-LENGTH is also used when writing VB recs. You put the length of the OP rec there before the rec is written. You can calculate it or use the value of the read rec.
In some cases you may have a variety of recs with differing lengths in the IP file. In this case you don't need the DEPENDING ON phrase. You can provide a different 01 level in the FD for each type rec in the IP. Usually each rec type should contain a field that that uniquely identifies the rec type to the pgm. You use that field to identify what rec type you just read.
To WRITE the rec use the 01 level variable name for that type in the WRITE stmt, e.g. WRITE REC-TYPE1.