I vaguely remember that any variable name followed by -length denotes the length of data in that variable. Is that correct ? I could not find this anywhere after search though.
Infact , I am dealing with a cobol program in which length of the variable is defined separately as NFT-MISC-DATA-LENGTH. while writing output to the file, only NFT-MISC-DATA is being populated. I am getting garbage in the variable length in the output, which is as expected.
But I see a number of Old records added in that file which have correct length. I checked a much older version of program and the code is same.
If -LENGTH followed by variable name does not automatically imply length of variable then I guess the length might have been written out from some other source.
If that is a parameter, explicit or implicit, to something which expects the data to be like that (say SQL and an host-variable VARCHAR of maximum length 20,000 bytes) then that is how it would work. Name is irrelevant.
05 apple BINARY PIC 9(8).
10 FILLER OCCURS 20000
DEPENDING ON apple.
15 FILLER PIC X.
That's your own variable-length field. The name, again, does not matter. Here, in addition, the location of apple does not matter (as long as it doesn't itself have a variable location).
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
Remember that the LENGTH OF special register is the length of the PICTURE, not the length of the data inside the field. To get the length of the data, I usually use a combination of FUNCTION REVERSE and INSPECT xxx TALLYING LEADING SPACES.