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

Breaking Input into different variables


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

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Tue Dec 04, 2007 7:18 am
Reply with quote

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. icon_biggrin.gif
Back to top
View user's profile Send private message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Tue Dec 04, 2007 8:18 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Dec 04, 2007 9:21 am
Reply with quote

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
View user's profile Send private message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Tue Dec 04, 2007 10:53 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Dec 04, 2007 8:38 pm
Reply with quote

You're welcome icon_smile.gif

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
View user's profile Send private message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Wed Dec 05, 2007 1:21 pm
Reply with quote

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. icon_biggrin.gif

-wicked
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Dec 05, 2007 1:37 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Dec 05, 2007 8:42 pm
Reply with quote

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
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts force tablespace using LISTDEF input DB2 1
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
No new posts Use input file with OMIT rcd keys? DFSORT/ICETOOL 15
Search our Forums:

Back to Top