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

Can i do it with unstring clause in COBOL


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

New User


Joined: 15 Feb 2006
Posts: 18

PostPosted: Thu Jul 12, 2007 8:10 am
Reply with quote

I have a variable lets say A with PIC clause X(40).

01 A PIC X(40) VALUE 'GARG,RAJIV KUMAR'

I want to unstring it and move it in the new variable such that the B has value as follows

01 B
05 B-FIRST-NAME PIC X(10) value moved should be RAJIV
05 B-MIDDLE-NAME PIC X(10) value moved should be KUMAR
05 B-LAST-NAME PIC X(10) value moved should be GARG

Can i do it with unstring clause in COBOL. If no, how can i possible do it? Again this all is dynamic. May be sometimes i don't get the middle name i.e. GARG

Thanks and Regards,
Rajiv Garg
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 Jul 12, 2007 8:35 am
Reply with quote

Hello,

If your data will not be predictable, you will probably not be able to use the UNSTRING function to do what you want. If there is a way to ensure that the name field will always have the first, middle, and last name or at least an agreed upon delimiter when there is no corresponding data, you may be able to use UNSTRING.

If you have unpredictable data, your task will be more difficult. You will need to determine some rules, break the 40 byte field 1nto at least 4 smaller fields (last, first, middle, other), and then apply the rules to the values in those fields. Can you be sure the order of the name field will be the same? You will also need to determine if the comma, the space, or something else might be used as a delimiter.

If this is a typo, please let me know and i'll correct it.
Quote:
May be sometimes i don't get the middle name i.e. GARG
Should GARG be last name?
Back to top
View user's profile Send private message
rgarg

New User


Joined: 15 Feb 2006
Posts: 18

PostPosted: Thu Jul 12, 2007 8:43 am
Reply with quote

I am sorry for the typo. Yes, GARG is the last name. Kumar is the Middle name.

Yes the format i receive is same always and is as follows

GARG,RAJIV KUMAR

LAST NAME,FIRST NAME MIDDLE NAME

i.e. Comma between last name and first name(GARG,RAJIV). Space between first name and middle name(RAJIV KUMAR)

But may be there will be no middle name(KUMAR) sometimes. Then how will i divide the corresponding fields.

Thanks and Regards
Rajiv Garg
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 Jul 12, 2007 8:47 am
Reply with quote

Hello,

Will any part of a name ever have a space in it?
Back to top
View user's profile Send private message
rgarg

New User


Joined: 15 Feb 2006
Posts: 18

PostPosted: Thu Jul 12, 2007 8:54 am
Reply with quote

Yes, there is space between first name and middle name. Another example

DRFNE,IRMIE R

Here last name is DRFNE
first name is IRMIE
middle name is R

This is the format i will receive everytime. Now i need to break it in first,middle and last name. Can you please help me with this

Thanks and Regards
Rajiv Garg
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jul 12, 2007 10:04 am
Reply with quote

Unstring will work just fine, go for it.....
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 Jul 12, 2007 7:27 pm
Reply with quote

Hello,

I don't believe i've made my question quite clear.

Might there ever be a name like
DRFNE,IRMIE R DONALD or
DRFNE,IRMIE RON DON or
DRFNE,IRMIE JOE RONALD where IRMIE JOE is the first name and RONALD is the middle name
(with a 2-part first or middle name)?

If the name will always be like DRFNE,IRMIE R and the only variance is that sometimes there may be a middle initial instead of a middle name, UNSTRING should do what you want.
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top