IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Counting characters in a string and splitting the string


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
meen

New User


Joined: 23 Jun 2008
Posts: 15
Location: bangalore

PostPosted: Fri Aug 14, 2009 12:04 pm
Reply with quote

My requirement is to Count the number of characters in a string. After counting I need to divide this string into small strings. Suppose after counting I got the number of characters as 95.. Now I need to divide this into strings of 10 characters each.

Pls suggest how to do this?

Thanks in Advance
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Fri Aug 14, 2009 12:25 pm
Reply with quote

Hi,
Use a perform vaying to move the 10 10 byte of the string and keep a diff counter for the lenght of the string you can achive the desired result

Hope this help

Ketan
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Fri Aug 14, 2009 12:48 pm
Reply with quote

Calculate the lenght of string first :

PERFORM VARYING var FROM length_of_string BY -1 UNTIL var < 1 OR string(var:1) NOT = SPACE
CONTINUE
END-PERFORM

DIVIDE length_of_string BY 10 GIVING length_of_string
REMAINDER WS-rem

If ws-rem not equal to zero
compute length_of_string = length_of_string +1
end-if


Define the splited vars with OCUURS clause in working storage as :

01 string pic x(99).
01 var-split redefines var pic x(99).
05 ws-split occurs 0 to 10 times depending on length_of_string .
10 ws-split-var pic x(10).
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Aug 14, 2009 5:04 pm
Reply with quote

Quote:
My requirement is to Count the number of characters in a string. After counting I need to divide this string into small strings. Suppose after counting I got the number of characters as 95.. Now I need to divide this into strings of 10 characters each.

Pls suggest how to do this?
Your requirements are not clear enough to me to make suggestions. How long is the variable you're calling "a string" (not a standard COBOL term for a variable, by the way)? If the length is 1000 bytes and you're got 95 bytes scattered every 10 bytes or so, do you still want 10 outputs or 100 outputs? Do spaces count as characters in your requirement? Since COBOL does not allow variables to be undefined, pretty much by definition your variable will be fully populated with something -- SPACES, LOW-VALUES, junk data, or actual data.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Reading dataset in Python - New Line ... All Other Mainframe Topics 22
Search our Forums:

Back to Top