View previous topic :: View next topic
|
Author |
Message |
amitc23
New User
Joined: 05 Nov 2014 Posts: 95 Location: India
|
|
|
|
Hi
Just need to clarify this.
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.
Thanks |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
01 some-nice-data-name.
05 orange COMP-5 PIC 9(4).
05 the-actual-data PIC X(20000). |
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.
Code: |
01 some-nice-data-name.
05 apple BINARY PIC 9(8).
05 the-actual-data.
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). |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I vaguely remember that any variable name followed by -length denotes the length of data in that variable. Is that correct ? |
It might be true for some version of COBOL but it is not true for Enterprise COBOL. Use the intrinsic function LENGTH in Enterprise COBOL.[/quote] |
|
Back to top |
|
|
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
COBOL compiler does not automatically set the value of -LENGTH. You have to manually do it using
Code: |
MOVE LENGTH OF NFT-MISC-DATA TO NFT-MISC-DATA-LENGTH |
Note: the LENGTH OF construct is the byte length not the number of digits. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
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. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
amitc23 has wandered off, so we'll probably never find out what they actually wanted.
LENGTH OF is equivalent to FUNCTION LENGTH except in the case of DBCS data, where FUNCTION LENGTH will give the length in characters and LENGTH OF the length in bytes.
Both operate on the length of the field, not the length of the data.
Both work with variable-length fields. LENGTH OF is an IBM Extension, FUNCTION LENGTH is from the COBOL Standard.
Except in the case of variable-length fields, both are resolved at compile time, because the compiler knows the length of fixed-length fields.
It is eminently possible that none of this relates to amitc23's problem. |
|
Back to top |
|
|
|