IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Length of a variable in Cobol


 
IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: :: View next topic  
Author Message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Tue Jan 12, 2016 2:12 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix

PostPosted: Tue Jan 12, 2016 3:19 pm
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: 8566
Location: Dubuque, Iowa, USA

PostPosted: Tue Jan 12, 2016 6:11 pm
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: 195
Location: Toronto, ON, Canada

PostPosted: Tue Jan 19, 2016 12:37 am
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: 1249
Location: Richfield, MN, USA

PostPosted: Tue Jan 19, 2016 8:22 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix

PostPosted: Tue Jan 19, 2016 8:49 pm
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 All times are GMT + 6 Hours
Forum Index -> COBOL Programming
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts JCL for replacing code in Cobol JCL & VSAM 8
No new posts COBOL VS SORT Utility for file format... COBOL Programming 6
No new posts XML Parsing in COBOL creating "h... COBOL Programming 0
No new posts Calling Rexx program from Cobol CLIST & REXX 12
No new posts BMS map length field greater than zero CICS 3

Back to Top