Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Find the string length

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Find the string length
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    Post subject:
Reply with quote

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

Global Moderator


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

PostPosted: Mon Jun 13, 2011 6:20 pm    Post subject:
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

Moderator Team Head


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

PostPosted: Mon Jun 13, 2011 6:27 pm    Post subject: Reply to: Find the string length
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: 8201
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 13, 2011 6:36 pm    Post subject:
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

Site Director


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

PostPosted: Mon Jun 13, 2011 8:36 pm    Post subject: Reply to: Find the string length
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: 659
Location: Whitby, ON, Canada

PostPosted: Tue Jun 14, 2011 1:00 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
This topic is locked: you cannot edit posts or make replies. Selecting two copybooks of different ... Vignesh Sid COBOL Programming 8 Tue Sep 05, 2017 7:28 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us