How do u Calculate the total no of chars in string



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How do u Calculate the total no of chars in string

Postby ragur.satheesh » Mon Dec 13, 2010 12:02 pm

How do u calculate the total no of characters in string
ragur.satheesh
 
Posts: 17
Joined: Thu Jul 22, 2010 12:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

 

Re: How do u Calculate the total no of chars in string

Postby sriraj1122 » Mon Dec 13, 2010 2:07 pm

You can use INSPECT to count the characters in a variable.
sriraj1122
 
Posts: 19
Joined: Thu Nov 18, 2010 10:04 am
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

Postby Robert Sample » Mon Dec 13, 2010 5:10 pm

COBOL does not have "strings" in the sense other languages have strings (where the length can vary while the program is running). COBOL WORKING-STORAGE variables, whether numeric, alphabetic, or alphanumeric, are fixed length and that length is fixed at compile time. There are ways to simulate strings in COBOL but such techniques require some advanced knowledge of COBOL.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: How do u Calculate the total no of chars in string

Postby Srikk » Wed Dec 15, 2010 4:10 pm

Srikk
 
Posts: 3
Joined: Wed Dec 15, 2010 3:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

Postby FUFENG » Wed Dec 29, 2010 12:21 pm

there is a indirect way to solve this problem

specify the string is test-string

example:

UNSTRING TEST-string
DELIMITED BY
INTO COUNT1 COUNT IN LEN
DELIMITER IN STD.
FUFENG
 
Posts: 6
Joined: Wed Dec 29, 2010 12:00 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

Postby FUFENG » Sun Jan 02, 2011 1:08 pm

NOW,I FIND THE WAY TO SOLVE THIS QUESTION
EXAMPLE
MOVE LENGTH OF STRING1 TO A

IT'S USE LENGTH OF TO CALCULATE THE TOTAL NO OF CHANRS IN STRING
FUFENG
 
Posts: 6
Joined: Wed Dec 29, 2010 12:00 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

Postby FUFENG » Sun Jan 02, 2011 1:22 pm

OTHER
INSPECT STRING1 TALLYING FOR CHARACTERS BEFORE L

YOU CAN USE THIS TO CALCULATE THE TOTAL NO OF CHARS
FUFENG
 
Posts: 6
Joined: Wed Dec 29, 2010 12:00 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How do u Calculate the total no of chars in string

Postby dick scherrer » Mon Jan 03, 2011 10:28 am

Hello,

Neither of your "solutions" is completely true/useful. . .

Both will execute, but the results will most likely be different. . .

Also, turn off your CAPS LOCK. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How do u Calculate the total no of chars in string

Postby Schubie » Wed Jan 05, 2011 11:58 am

1) What is the "delimiter'"? For the sake of discussion, let's assume it to be a space. 2) What defines "characters in a string"? If the "string" is a name like "George Washington", the lenght of the "string" is 17 characters. This could be determined by redefining the variable as a table and count from the end until the first non-space character is reached. If we count from the left until the first delimiter (aka space) is reached, the routine would only count 6 characters. If we simply count non-space characters, the result would be 16. These are not COBOL issues, I'd ask the same for any programming language.
If a bug is located in a program product which simply cannot be fixed, it becomes a 'feature'. (IBM)
User avatar
Schubie
 
Posts: 10
Joined: Wed Jul 21, 2010 9:16 am
Location: Blue Ridge, GA USA
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post