## 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

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

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

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: 3098
Joined: Sat Dec 19, 2009 8:32 pm
Location: Bellevue, Iowa
Has thanked: 1 time
Been thanked: 176 times

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

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

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

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

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

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.

dick scherrer
Global moderator

Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

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

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)

Schubie

Posts: 10
Joined: Wed Jul 21, 2010 9:16 am
Location: Blue Ridge, GA USA
Has thanked: 0 time
Been thanked: 0 time