Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Breaking Input into different variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Breaking Input into different variables
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    Post subject: Reply to: Breaking Input into different variables
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

Site Director


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

PostPosted: Tue Dec 04, 2007 9:21 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Dec 04, 2007 8:38 pm    Post subject: Reply to: Breaking Input into different variables
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10308
Location: italy

PostPosted: Wed Dec 05, 2007 1:37 pm    Post subject: Reply to: Breaking Input into different variables
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

Site Director


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

PostPosted: Wed Dec 05, 2007 8:42 pm    Post subject:
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    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 SORT Trailer Count - LRECL Output co... amorante DFSORT/ICETOOL 5 Tue Aug 29, 2017 8:57 pm
No new posts Getting Mutiple input from Panels vidyaa CLIST & REXX 12 Mon Aug 14, 2017 1:28 pm
No new posts How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm
No new posts Need input in Scheduling Benchwarmer CA Products 5 Tue Jun 06, 2017 1:44 am
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us