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
 

 

Need to separate a string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Need to separate a string
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: 2150
Location: At my coffee table

PostPosted: Wed Apr 22, 2009 12:21 am    Post subject:
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    Post subject: Reply to: Need to separate a string
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

Site Director


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

PostPosted: Wed Apr 22, 2009 3:25 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Apr 22, 2009 3:45 am    Post subject:
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    Post subject: Reply to: Need to separate a string
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Wed Apr 22, 2009 9:37 pm    Post subject:
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: 24
Location: bangalore

PostPosted: Thu Apr 30, 2009 12:53 pm    Post subject:
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

Site Director


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

PostPosted: Thu Apr 30, 2009 1:27 pm    Post subject:
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: 24
Location: bangalore

PostPosted: Fri Jul 17, 2009 4:07 pm    Post subject:
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    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
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
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


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