Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
hariibm

New User

Joined: 05 Feb 2007
Posts: 61
Location: Chennai

 Posted: Thu Mar 01, 2007 11:31 pm    Post subject: Find the Length of the character string without using STRING 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

William Thompson

Global Moderator

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

 Posted: Thu Mar 01, 2007 11:48 pm    Post subject: 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
mmwife

Super Moderator

Joined: 30 May 2003
Posts: 1592

Posted: Fri Mar 02, 2007 8:13 am    Post subject:

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).
agkshirsagar

Active Member

Joined: 27 Feb 2007
Posts: 686
Location: Earth

Posted: Fri Mar 02, 2007 1:09 pm    Post subject:

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)
agkshirsagar

Active Member

Joined: 27 Feb 2007
Posts: 686
Location: Earth

Posted: Fri Mar 02, 2007 1:29 pm    Post subject:

Sorry
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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics RACF- How to find the Last access of ... rahul shanmuganatan All Other Mainframe Topics 6 Thu Jun 21, 2018 3:19 pm To remove spaces in a variable length... Selvarajars JCL & VSAM 1 Thu Jun 21, 2018 1:07 pm Removing spaces before the tab character V S Amarendra Reddy SYNCSORT 1 Thu Jun 14, 2018 8:45 am Rexx code to find greater then symobl... Bharath Vikraman CLIST & REXX 8 Tue May 29, 2018 9:40 am Splitting one row into multiple Rows ... Rajan Moorthy DFSORT/ICETOOL 9 Mon May 14, 2018 10:58 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us