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 Length of the character string without using STRING

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Thu Mar 01, 2007 11:31 pm    Post subject: Find the Length of the character string without using STRING
Reply with quote

Hi All,

Please provide me with a peace of code to get the length of a character string.(without using INSPECT verb).

Ex:
01 A PIC X(40).

MOVE 'IBM FORUMS.COM' TO A.

I know LENGTH OF gives the length as 40. But it should give only 14 as the actual length of the string is 14.

Thanks,
Hari
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Mar 01, 2007 11:48 pm    Post subject:
Reply with quote

Something like this could be used where x is a counter and length will be your length:
perform varying x from 40 by -1 until x is less than 1
if a(x:1) not = space move x to length move zero to x end-if
end-perform
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Mar 02, 2007 8:13 am    Post subject:
Reply with quote

Hi hariibm,

Give this a try:
Code:
  01  TEXT1           PIC  X(010) VALUE '12AB'.


INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L

After the INSPECT L contains a 6.

After the COMPUTE it contains 4 (10 - 6), the length of the string (12AB).
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Fri Mar 02, 2007 1:09 pm    Post subject:
Reply with quote

Jack, hari wants it without using INSPECT verb.
Following code should serve the purpose
Code:

PERFORM VARYING I FROM 39 BY -1           
    UNTIL A(I:1) NOT= SPACES   
END-PERFORM                               
DISPLAY 'LENGTH OF STR : ' I.


I have hardcoded 39 in the loop. We can use one var that contains value (LENGTH OF A - 1)
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Fri Mar 02, 2007 1:29 pm    Post subject:
Reply with quote

Sorry icon_redface.gif
A little correction in above code.
Code:

PERFORM VARYING I FROM LENGTH OF A BY -1           
    UNTIL A(I:1) NOT= SPACES   
END-PERFORM                               
DISPLAY 'LENGTH OF STR : ' I.
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 Extra character appears in file when ... Balu5491 All Other Mainframe Topics 1 Wed Jul 26, 2017 2:39 pm
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


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