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
 
How to calculate length of a string

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

New User


Joined: 06 Jun 2005
Posts: 2
Location: India-Pune

PostPosted: Mon Jun 06, 2005 2:36 pm    Post subject: How to calculate length of a string
Reply with quote

Folks

I have requirement

01 WK-CIRCUIT-DATA PIC X(43)

User Data : 1000104104 T3X-13 HRFRCT03K16 HRFRCT03W01

Length of the user data is 41 (including 3 blank spaces between the data)

Kindly suggest me a method where by I can compute the length of the user data including spaces between the data (3 in the above eg) and excluding trailing spaces(2 in the above eg)

I should get 41 as the ans.

Thanks in advance

Rohit
Back to top
View user's profile Send private message

priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Tue Jun 07, 2005 8:34 pm    Post subject:
Reply with quote

Try INSPECT verb.
Back to top
View user's profile Send private message
lucky

New User


Joined: 01 Jun 2005
Posts: 12
Location: Croatia

PostPosted: Wed Jun 08, 2005 12:49 pm    Post subject: Re: How to calculate length of a string
Reply with quote

I'm a C programmer, so I can't write you the COBOL code, but I would do this:
1.) Get the total length of the string (in your case 43)
2.) Loop through the string from the end backwards, and get the value of each character (I believe it's POSITION statement in COBOL).
3.) If the character is a space, decrease the variable from step 1 by 1.
4.) Break on first non-space character.

As I said, I'm a C programmer, so I don't knoe if there is a better way in COBOL.
Back to top
View user's profile Send private message
sivatechdrive

Active User


Joined: 17 Oct 2004
Posts: 190
Location: hyderabad

PostPosted: Wed Jun 08, 2005 3:45 pm    Post subject: Re: How to calculate length of a string
Reply with quote

Hi rohit

try the below code

PERFORM VARYING WS-SUB-NAME FROM LENGTH OF WS-VAR BY -1
UNTIL END-FOUND OR WS-SUB-NAME = 0
IF WS-NAME-CHK(WS-SUB-NAME:1) NOT EQUAL TO SPACE
MOVE 'Y' TO WS-END-OF-FIELD
DISPLAY 'LENGTH ' WS-SUB-NAME
END-IF
END-PERFORM


Regards
siva
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