IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Find the string length


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

New User


Joined: 17 Jun 2010
Posts: 6
Location: chennai

PostPosted: Mon Jun 13, 2011 5:28 pm
Reply with quote

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
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Mon Jun 13, 2011 5:41 pm
Reply with quote

Refer this - ibmmainframes.com/about4550.html
ibmmainframes.com/about8575.html
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 13, 2011 6:20 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Mon Jun 13, 2011 6:27 pm
Reply with quote

I wonder why this seems to be a new recurring topic as of late?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 13, 2011 6:36 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jun 13, 2011 8:36 pm
Reply with quote

Current homework assignment icon_neutral.gif

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
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Tue Jun 14, 2011 1:00 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top