View previous topic :: View next topic
|
Author |
Message |
rgarg
New User
Joined: 15 Feb 2006 Posts: 18
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
rgarg
New User
Joined: 15 Feb 2006 Posts: 18
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Will any part of a name ever have a space in it? |
|
Back to top |
|
|
rgarg
New User
Joined: 15 Feb 2006 Posts: 18
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Unstring will work just fine, go for it..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|