Page 1 of 2

Find the Length of the data stored in working storage variab

PostPosted: Tue Jul 29, 2008 1:37 pm
by SANDHYA BUDHI
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.

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

PostPosted: Wed Jul 30, 2008 12:23 am
by dick scherrer
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.

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

PostPosted: Thu Aug 14, 2008 10:56 pm
by ddilts399
INSPECT FUNCTION REVERSE(fieldname)
TALLYING WS-TALLY FOR LEADING SPACES

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

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

PostPosted: Fri Aug 22, 2008 3:45 pm
by riteshk.singh
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."

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

PostPosted: Sat Aug 23, 2008 6:07 am
by dick scherrer
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?

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

PostPosted: Sat Aug 23, 2008 4:20 pm
by riteshk.singh
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

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

PostPosted: Sun Oct 28, 2012 8:07 pm
by raghuvanshi
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

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

PostPosted: Sun Oct 28, 2012 8:41 pm
by BillyBoyo
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.

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

PostPosted: Mon Oct 29, 2012 3:54 am
by dick scherrer
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. . .

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

PostPosted: Mon Oct 29, 2012 12:50 pm
by raghuvanshi
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.