Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Length of a variable in Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
amitc23

New User


Joined: 05 Nov 2014
Posts: 78
Location: India

PostPosted: Tue Jan 12, 2016 2:12 pm    Post subject: Length of a variable in Cobol
Reply with quote

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
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Tue Jan 12, 2016 3:19 pm    Post subject: Reply to: Length of a variable in Cobol
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Tue Jan 12, 2016 6:11 pm    Post subject: Reply to: Length of a variable in Cobol
Reply with quote

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
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 183
Location: Toronto, ON, Canada

PostPosted: Tue Jan 19, 2016 12:37 am    Post subject:
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1238
Location: Richfield, MN, USA

PostPosted: Tue Jan 19, 2016 8:22 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Tue Jan 19, 2016 8:49 pm    Post subject: Reply to: Length of a variable in Cobol
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us