Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 8117
Location: East Dubuque, Illinois, 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: 4649
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: 8117
Location: East Dubuque, Illinois, 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: 654
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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
No new posts Length of Tape file Mohan Kothakota JCL & VSAM 9 Thu Apr 20, 2017 10:24 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us