View previous topic :: View next topic
|
Author |
Message |
arulkumar
New User
Joined: 17 Jun 2010 Posts: 6 Location: chennai
|
|
|
|
Hi,
I am having the variables ws-err and ws-len as below,
01 groups.
05 ws-err pic x(40).
05 ws-len pic 9(2).
move 'lion is an animal' to ws-err
I want to find out the length of ws-err
My result should be 17. ws-len should be 17. |
|
Back to top |
|
|
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Terminology is critial in IT, where similar terms may mean very different things. COBOL does not have "strings" like C, Basic, Perl, Java, and other languages. The length of a variable is set at compile time (except for OCCURS DEPENDING ON variables in the LINKAGE SECTION), and cannot be changed. The length of your variable (not string) ws-err is 40, period.
If you want to find the number of characters in the variable, you can use
Code: |
MOVE ZERO TO WS-LEN.
INSPECT FUNCTION REVERSE (WS-ERR)
TALLYING WS-LEN FOR LEADING SPACES.
COMPUTE WS-LEN = 40 - WS-LEN. |
|
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
I wonder why this seems to be a new recurring topic as of late? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Good question, Kevin. Lack of training? Too many ex-C programmers converting to mainframe? Lack of ability of posters to use the Search button on this website? All sorts of possibilities, I think. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Current homework assignment
RantOn
And once again there are many who would learn, but are being fed this kind of nonsense instead of doing something worthwhile. . .
RandOff
d |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
IMO it shows a lack of elementary programming skills. I wouldn't expect a Cobol rookie to come up with INSPECT FUNCTION REVERSE (my favourite technique) on the first try but they should at least be able to come up with the more traditional loop-based approach, which will work in just about every programming language that supports arrays. Anyone who can't do that should reconsider their career choice. |
|
Back to top |
|
|
|