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

Need to separate a string


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

New User


Joined: 18 Mar 2008
Posts: 34
Location: INDIA

PostPosted: Wed Apr 22, 2009 12:09 am
Reply with quote

I have a string say ' Rajesh Kumar Sinha' which i am getting from a file record and can be of maximum length of 50

I want result in 3 variables as

First name = Rajesh
Middle name = Kumar
Last name = Sinha

what is the best possible way to get the result?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Apr 22, 2009 12:21 am
Reply with quote

Start with the UNSTRING statement.....
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Wed Apr 22, 2009 3:22 am
Reply with quote

Certainly unstring suits best for your requirement.....try reference modification ....probably the second best in this context icon_biggrin.gif.
WTF
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 22, 2009 3:25 am
Reply with quote

Hello,

As posted, a simple UNSTRING will decompose the 3-part name into 3 separate fields.

If you are not already comfortable with UNSTRING, i'd suggest you write the code needed to read a bt of 3-part test names and unstring them.

Then, you might consider additional functionality - like: What should happen when there are only 2 name "pieces" or if there are 4.
Back to top
View user's profile Send private message
dilpreet

New User


Joined: 18 Mar 2008
Posts: 34
Location: INDIA

PostPosted: Wed Apr 22, 2009 3:38 am
Reply with quote

Is this the way to do this

Unstring Input
delimited by Spaces into field1, field2, field3
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 22, 2009 3:45 am
Reply with quote

Hello,

Basically, yes.

Suggest you compile the code and run a few different sets of input data.

Before issuing the unstring, move spaces to the output area(s).
Back to top
View user's profile Send private message
dilpreet

New User


Joined: 18 Mar 2008
Posts: 34
Location: INDIA

PostPosted: Wed Apr 22, 2009 4:13 pm
Reply with quote

Thanks alot
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Apr 22, 2009 9:33 pm
Reply with quote

You might want to code for the possibility of having more than 1 space between names.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Apr 22, 2009 9:37 pm
Reply with quote

When DELIMITED BY ALL is not specified, and two or more contiguous occurrences of any delimiter are encountered, the current data receiving field (identifier-4) is filled with spaces or zeros, according to the description of the data receiving field.
Back to top
View user's profile Send private message
mnnarayankar

New User


Joined: 21 Jan 2008
Posts: 23
Location: bangalore

PostPosted: Thu Apr 30, 2009 12:53 pm
Reply with quote

Hi,

This is very simplest work. you can do it by unstring as well reference modification.

But I would like to say you use reference modification.
First name = Rajesh
Middle name = Kumar
Last name = Sinha

String - 'Rajesh Kumar Sinha'

move Rajesh Kumar Sinha(1:6) to First-name.
move Rajesh Kumar Sinha(8:5) to Middle-name.
move Rajesh Kumar Sinha(15:5) to Last-name.

and display all variable you will get your answer.

Thanks & Regards,

Mohan Nagnath Narayankar
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Apr 30, 2009 1:27 pm
Reply with quote

Hello,

Code:
move Rajesh Kumar Sinha(1:6) to First-name.
move Rajesh Kumar Sinha(8:5) to Middle-name.
move Rajesh Kumar Sinha(15:5) to Last-name.
will only work for one name "pattern". If the name is "Mohan Nagnath Narayankar" the code won't work properly.

Suggest the unstring is far more flexible. . .
Back to top
View user's profile Send private message
mnnarayankar

New User


Joined: 21 Jan 2008
Posts: 23
Location: bangalore

PostPosted: Fri Jul 17, 2009 4:07 pm
Reply with quote

Yes Dick You are correct.

Sorry for misguide. If reading a data from file then best option to be used is UNSTRING.


Thanks & Regards,
Mohan Narayankar
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 file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top