Find the Length of the data stored in working storage variab



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Find the Length of the data stored in working storage variab

Postby SANDHYA BUDHI » Tue Jul 29, 2008 1:37 pm

I have to find the length of the data which is stored in a working storage variable. Suppose in the working storage varaible ws-example I have the value "Welcome" . The ws-example is declared as PICx(20). I want to find the length of the data stored.

I want the length as 7 ("WELCOME") and not 20.

I have used the FUNCTION LENGTH(ws-example) but it is giving the length as 20 but not 7.
SANDHYA BUDHI
 
Posts: 19
Joined: Mon Jul 21, 2008 7:52 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Find the Length of the data stored in working storage variab

 

Re: Find the Length of the data stored in working storage variab

Postby dick scherrer » Wed Jul 30, 2008 12:23 am

Hello,

Using an array or reference modification, loop from the right side of the field counting the blanks until you reach a non-blank. (20 - the count) will be the data length.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Find the Length of the data stored in working storage variab

Postby ddilts399 » Thu Aug 14, 2008 10:56 pm

INSPECT FUNCTION REVERSE(fieldname)
TALLYING WS-TALLY FOR LEADING SPACES

COMPUTE WS-TOTAL-BYTES = LENGTH OF fieldname - WS-TALLY
ddilts399
 
Posts: 1
Joined: Thu Aug 14, 2008 9:05 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Find the Length of the data stored in working storage variab

Postby riteshk.singh » Fri Aug 22, 2008 3:45 pm

INSPECT <your string variable> TALLYING <variable to store length> FOR CHARACTERS BEFORE <delimitor>.

Note: give some delimitor at the end of the name like "WELCOME."
riteshk.singh
 
Posts: 4
Joined: Thu Aug 21, 2008 11:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Find the Length of the data stored in working storage variab

Postby dick scherrer » Sat Aug 23, 2008 6:07 am

Hello riteshk.singh and welcome to the forums,

Note: give some delimitor at the end of the name like "WELCOME."
Is there some reason you prefer to require a delimiter/terminator character rather than use the INSPECT previously suggested?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Find the Length of the data stored in working storage variab

Postby riteshk.singh » Sat Aug 23, 2008 4:20 pm

the ispect previously suggested will also work fine. :)

INSPECT FUNCTION REVERSE(fieldname)
TALLYING WS-TALLY FOR LEADING SPACES

COMPUTE WS-TOTAL-BYTES = LENGTH OF fieldname - WS-TALLY
riteshk.singh
 
Posts: 4
Joined: Thu Aug 21, 2008 11:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Find the Length of the data stored in working storage va

Postby raghuvanshi » Sun Oct 28, 2012 8:07 pm

ddilts399 wrote:INSPECT FUNCTION REVERSE(fieldname)
TALLYING WS-TALLY FOR LEADING SPACES

COMPUTE WS-TOTAL-BYTES = LENGTH OF fieldname - WS-TALLY


Hi ddilts,

Here if we have trailing spaces as well can we write as
INSPECT FUNCTION REVERSE(fieldname)
   TALLYING WS-TALLY FOR LEADING AND TRAILING SPACES
raghuvanshi
 
Posts: 43
Joined: Tue Dec 07, 2010 5:32 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Find the Length of the data stored in working storage va

Postby BillyBoyo » Sun Oct 28, 2012 8:41 pm

Can you please show the compile output for that, including the error messages? So, no, we can't. No such thing as INSPECT FOR TRAILING in Enterprise Cobol or any IBM Mainframe Cobol.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Find the Length of the data stored in working storage va

Postby dick scherrer » Mon Oct 29, 2012 3:54 am

Hello,

INSPECT FUNCTION REVERSE(fieldname)
   TALLYING WS-TALLY FOR LEADING AND TRAILING SPACES
Do Not post untested syntax that you Thought looked OK. You need to verify a clean compile as well as a successful test showing both the input and output.

All this does is introduce clutter and for inexperienced people causes confusion. . .
Hope this helps,
d.sch.

These users thanked the author dick scherrer for the post:
raghuvanshi (Mon Oct 29, 2012 8:14 am)
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Find the Length of the data stored in working storage va

Postby raghuvanshi » Mon Oct 29, 2012 12:50 pm

I think this analogy will work for spaces on either side of the required data field
move 1 to b
perform varying b from 1 by 1 until b>30(any +ve integer)
move a(b:1) to a1
display a1
if a1is not = " " then
display 'inside' a1
add 1 to c
end-if.
end-perform.
display 'c reached' c.
raghuvanshi
 
Posts: 43
Joined: Tue Dec 07, 2010 5:32 pm
Has thanked: 3 times
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post