Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Counting characters in a string and splitting the string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Counting characters in a string and splitting the string
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    Post subject:
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    Post subject:
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: 7932
Location: Bellevue, IA

PostPosted: Fri Aug 14, 2009 5:04 pm    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us