View previous topic :: View next topic
|
Author |
Message |
dilpreet
New User
Joined: 18 Mar 2008 Posts: 34 Location: INDIA
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Certainly unstring suits best for your requirement.....try reference modification ....probably the second best in this context .
WTF |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dilpreet
New User
Joined: 18 Mar 2008 Posts: 34 Location: INDIA
|
|
|
|
Is this the way to do this
Unstring Input
delimited by Spaces into field1, field2, field3 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dilpreet
New User
Joined: 18 Mar 2008 Posts: 34 Location: INDIA
|
|
|
|
Thanks alot |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
You might want to code for the possibility of having more than 1 space between names. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
mnnarayankar
New User
Joined: 21 Jan 2008 Posts: 23 Location: bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
mnnarayankar
New User
Joined: 21 Jan 2008 Posts: 23 Location: bangalore
|
|
|
|
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 |
|
|
|