View previous topic :: View next topic
|
Author |
Message |
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
Hi,
I have a varying input same as below, (Lastname, First Name, MI):
Doon, Maria Cristina S.
Foronda, Maria Fatima P.
Fenomeno, Mc Arthur G.
Onia, Robert-Jan V.
I am required to break the above input into 3 variables (WS-LNAME, WS-FNAME, WS-MI).
How can I do this using the UNSTRING verb? Replies will appreciated. |
|
Back to top |
|
|
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
I was able to separate the surname from the rest just by the unstring verb, my only problem is the firsname and middle initial.
how can I do it using the INSPECT verb? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Before you can implement a solution, you must define the rules. The rules have not been posted yet.
You need to define all of the ways the name components might happen. Will there always be exactly one comma? What if a first name had 3 "pieces"? What if a lst name has 2 or more "pieces"? Will there always be a middle initial? Probably not. What if the name was like the author "L Ron Hubbard" (Hubbard, L Ron)?
I suspect that your solution will not be INSPECT.
If you post all of the rules, we may be able to offer suggestions. |
|
Back to top |
|
|
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
thanks for the reply dick.
Let me clarify my post..
Yes, there will always be a comma after the last name, and reagardless of how many first name the person has it must be separated into each variables (W-LNAME, W-FNAME, W-MI). My marker will be the period after the MI, which in in case always present in each record.
declaration will be:
W-LAST-NAME PIC X(19)
W-FIRST-NAME PIC X(20)
W-MIDDLE-INITIAL PIC X
actually I just the coding right. I'll just share it in case anyone encounters the same req. in the future.
Code: |
A1000-MAINLINE.
SORT SORT-FILE ON ASCENDING S-FIRST-NAME, S-MIDDLE-INITIAL,
S-LAST-NAME
INPUT PROCEDURE IS A2000-INPUT-SORT
GIVING SORTED-ADV-CBL-BATCH-2007-12.
STOP RUN.
A2000-INPUT-SORT.
MOVE ZERO TO CTR1
OPEN INPUT ADV-CBL-BATCH-2007-12
READ ADV-CBL-BATCH-2007-12
AT END MOVE 1 TO EOF-SW.
PERFORM A2100-DATA-LOOP UNTIL EOF-SW = 1.
CLOSE ADV-CBL-BATCH-2007-12.
A2100-DATA-LOOP.
UNSTRING INPUT-REC DELIMITED BY ','
INTO W-LAST-NAME, WS-FNAME.
INSPECT WS-FNAME TALLYING CTR1 FOR CHARACTERS BEFORE '.'
MOVE WS-FNAME(CTR1:1) TO W-MIDDLE-INITIAL
MOVE WS-FNAME(1:CTR1 - 2) TO W-FIRST-NAME
MOVE ZERO TO CTR1
MOVE W-LAST-NAME TO S-LAST-NAME
MOVE W-FIRST-NAME TO S-FIRST-NAME
MOVE W-MIDDLE-INITIAL TO S-MIDDLE-INITIAL
RELEASE SORT-RECORD.
READ ADV-CBL-BATCH-2007-12
AT END MOVE 1 TO EOF-SW.
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
Quote: |
My marker will be the period after the MI, which in in case always present in each record. |
As long as this remains true, INSPECT will be your friend.
Thank you for posting your solution.
Just curious though, what about people with no middle name/initial? |
|
Back to top |
|
|
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
Hi Dick,
I think as per requirements that would not be possible. These are names of students in a particular class so we can assume that they have a complete name.
-wicked |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
These are names of students in a particular class so we can assume that they have a complete name. |
that' maybe the way You got it in Your Homework...
or You imply that "BY LAW" in some countries everybody is bound
to have at least two names ??? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
These are names of students in a particular class so we can assume that they have a complete name. |
Why can we assume they have a middle name/initial? I once did some work for a major university involving the student population and hundreds of the students had no middle name/initial recorded (the student population was around 25,000).
If your data is "controlled" and every record will have a middle initial, fine, but when you get into real-world situations this will not always be true. As was mentioned, there is no law that says everyone has to have a middle name'initial. |
|
Back to top |
|
|
|