What is the difference between INSPECT and FUNCTION LENGTH?

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Abhilash Sharma
New Member
Posts: 6
Joined: Wed Jun 11, 2014 8:29 am

What is the difference between INSPECT and FUNCTION LENGTH?

Post by Abhilash Sharma »

Hi,

I want to find length of a field. Once I know that I'll pad zeroes. But I am not sure if I should this using INSPECT or with intrinsic FUNCTION LENGTH. What is the difference between the two approaches, I'm confused?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: What is the difference between INSPECT and FUNCTION LENG

Post by Robert Sample »

If your variable is in WORKING-STORAGE, the length does not change, ever. So FUNCTION LENGTH will only return one value no matter what data is stored in the variable. INSPECT allows you to locate the last byte of relevant data in the variable.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: What is the difference between INSPECT and FUNCTION LENG

Post by William Collins »

Can you show an example of what you are trying to do?
Abhilash Sharma
New Member
Posts: 6
Joined: Wed Jun 11, 2014 8:29 am

Re: What is the difference between INSPECT and FUNCTION LENG

Post by Abhilash Sharma »

I've a field which migh tcome like this "$$$$$1234" or "$$$$$$234" or "$$$$$$$34" or "$$$$$$$$4" or "$$$$$$$$$", where $ represents a space and it might alos be like "1234$$$$$" etc. I need to replace $ with a zero.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: What is the difference between INSPECT and FUNCTION LENG

Post by Robert Sample »

Use INSPECT or reference modification.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: What is the difference between INSPECT and FUNCTION LENG

Post by zprogrammer »

Are you sure "1234$$$$$" replacing $ with 0 for this type is correct?
Don't you need any justification?
zprogrammer
Abhilash Sharma
New Member
Posts: 6
Joined: Wed Jun 11, 2014 8:29 am

Re: What is the difference between INSPECT and FUNCTION LENG

Post by Abhilash Sharma »

I'd need justifcation too. I'll try with INSPECT and reference modification.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: What is the difference between INSPECT and FUNCTION LENG

Post by zprogrammer »

Try FUNCTION NUMVAL
zprogrammer
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”