MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to the length of a string

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
jagan
Beginner


Joined: 27 Jan 2003
Posts: 5
Topics: 4

PostPosted: Thu Mar 06, 2003 10:30 am    Post subject: how to the length of a string Reply with quote

hi friends,
i want to know the actual length of a value in a variable.
suppose i have a variable xcob with 40 size.
xcob pic x(40)
after i moved some value to that xcob.
is there any length verb in cobol?
length(xocb)

thanks
jagan
Back to top
View user's profile Send private message Yahoo Messenger
hari_uss
Beginner


Joined: 19 Dec 2002
Posts: 78
Topics: 6
Location: Trivandrum, India

PostPosted: Thu Mar 06, 2003 10:47 am    Post subject: Reply with quote

MOVE FUNCTION REVERSE(XCOB) TO XCOB-REV.
INSPECT XCOB-REV TALLYING WS-COUNT
FOR LEADING SPACES.
COMPUTE WS-LENGTH = LENGTH OF XCOB - WS-COUNT.
DISPLAY 'LENGTH = ' WS-LENGTH.

Note: Untested code.
Back to top
View user's profile Send private message Send e-mail
Grant
Beginner


Joined: 02 Dec 2002
Posts: 45
Topics: 1
Location: Sydney, NSW, Australia

PostPosted: Thu Mar 06, 2003 5:23 pm    Post subject: Reply with quote

Jagan,
The solution provided by hari_uss will work, but it will require a subroutine call to be generated for MOVE FUNCTION REVERSE(XCOB) TO XCOB-REV.

I think you will find that the following code will be pretty efficient

Code:

WORKING-STORAGE SECTION.                         
                                                 
01  X-COB     Pic X(100) value 'abcde'.         
01  I         Pic s9(4) binary.                 
                                                 
PROCEDURE DIVISION.                             
                                                 
    Perform varying I from length of X-COB by -1
      Until X-COB(I:1) not = spaces             
    End-perform                                 
                                                 
    Display "The value of I is " I               
                                                 
    GOBACK.                                     


The value of I is 0005
Back to top
View user's profile Send private message
ipog_jkm
Beginner


Joined: 28 Apr 2003
Posts: 2
Topics: 0

PostPosted: Tue Apr 29, 2003 6:01 am    Post subject: Reply with quote

Hi Jagan ,

You can use the following code

INSPECT WS-STRING TALLYING WS-COUNTER
FOR CHARACTERS BEFORE INITIAL SPACE

WS-STRING - STRING USED

WS-COUNTER - NO CHARACTERS.
Back to top
View user's profile Send private message
misfit
Beginner


Joined: 01 May 2003
Posts: 26
Topics: 9
Location: India

PostPosted: Thu May 01, 2003 12:52 am    Post subject: Reply with quote

hi ipog_jkm,

will this solution work for string having leading or embedded spaces?
_________________
<i><b> Don't wish it were easier. Wish you were better. </b></i>
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Thu May 01, 2003 2:17 am    Post subject: Reply with quote

No,

You will have to get count for both leading and trailing spaces seperately and then compute the length.

Diba.
Back to top
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Fri May 02, 2003 12:14 pm    Post subject: Reply with quote

This should work:

INSPECT WS-STRING TALLYING WS-L-SPACES
FOR CHARACTERS BEFORE INITIAL SPACE

INSPECT FUNCTION REVERSE (WS-STRING) TALLYING WS-T-SPACES
FOR CHARACTERS BEFORE INITIAL SPACE

COMPUTE WS-STRING-LEN
= LENGTH OF WS-STRING - WS-L-SPACES - WS-T-SPACES
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group