Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Thu Mar 08, 2007 8:36 am    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

Can anyone help in getting the cobolcode for converting Input Firstname*MI*Lastname to Lastname Firstname Middlename. The input is 30 bytes long (F*M*L) to output 30 bytes long to L F M.

Input: Van*Dame*start
output: Start Van Dame

Input: John**doe
output: Doe John
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: Thu Mar 08, 2007 8:42 am    Post subject:
Reply with quote

Hello,

Is the name field "*" delimited?

Will all 3 components always be populated (i.e. what about people with no middle name/initial?)? Please describe any "rules" concerning names at your organization.

Are you concerned about converting the first letter of the first&last name to upper case and the remainder to lower case? I only ask because of your example.
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Thu Mar 08, 2007 10:08 am    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

No, the three components will not always be populated. If you look the my second example as below . Some times Middle name is not populated.

Input: John**doe
output: Doe John

I am not concerned abt Upper case


Thanks for your Help
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Thu Mar 08, 2007 10:10 am    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

yes the delimiter is '*'.

Thanks
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Thu Mar 08, 2007 12:26 pm    Post subject:
Reply with quote

Vishwaroopa,
See the code below.
I have assumed that max length of First name is 15 char.

Code:

WORKING STORAGE SECTION.
01  WS-NAME PIC X(30).       
01  NAME.                       
 05  L            PIC X(15).     
 05  F            PIC X(15).     
 05  M            PIC X(15).     
* YOUR FORMAT IS L F M 

01  FINAL-NAME PIC X(30). 
PROCEDURE DIVISION.
MAIN-PARA.                                                 
    ACCEPT WS-NAME.                                       
    UNSTRING WS-NAME DELIMITED BY '*' INTO                 
          F,M,L.       
                                 
    STRING                                                 
        L,'@'                                             
        F,'@'                                             
        M,'@' DELIMITED BY SPACES                         
        INTO FINAL-NAME.                                   
    INSPECT FINAL-NAME REPLACING ALL '@' BY ' '.           
    DISPLAY FINAL-NAME
                                   

It will work provided your delimiter '*' is present. optimize/change the code as per your requirement.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Thu Mar 08, 2007 1:12 pm    Post subject:
Reply with quote

yes you can optimise the code using count-in and pointer clause in first unstring
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 95
Location: India

PostPosted: Thu Mar 08, 2007 6:15 pm    Post subject:
Reply with quote

The above code will work fine.
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Thu Mar 08, 2007 9:39 pm    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

Thanks to everybody for the Info. I didn't get the Idea of count-in and pointer clause . Can anyone give the syntax/explain
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: Thu Mar 08, 2007 9:40 pm    Post subject:
Reply with quote

Hello,

That info may be easily found in the Fine Manual that you may link to from this forum (at the top of the page, click on the "Manuals" link.
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Thu Mar 08, 2007 10:12 pm    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

Thanks for the Info.

I am facing two problems here
1. If I increase the size for L, F, M to 30 some other char get displayed at the end. As eg below

Input : BRETT*M*COX*
Output: COX BRETT M EGLINDE ZA

2. If there is a space in the lastname as below, it doesnt picks up the data after the space .

e.g 1
Inpout : VALERIE*J*WENDEL FILKINS*
output : WENDEL VALERIE J E NZA
e.g 2
Inpout : DON*L*ROBERTS SR*
output: ROBERTS DON L
Can any one pls let me know why is this and what fix is required.
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: Thu Mar 08, 2007 10:25 pm    Post subject:
Reply with quote

Hello,

You need to initialize the receiving area to spaces before each new name is processed.

If you post your code we can tell you wht the embedded space is not processed correctly.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Thu Mar 08, 2007 10:59 pm    Post subject:
Reply with quote

as dick said you had to initialize your identifiers to avoid that

for your second problem from the code given by agkshirsagar the last string statement uses spaces to delimit the data in identifiers F M and L to avoid that you need to put some data for example VALUE ALL '#' to all your F M and L and replace the line in STRING statement as DELIMITED BY '#' hope that will solve your problem
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: Thu Mar 08, 2007 11:22 pm    Post subject:
Reply with quote

Hello,

You might also use COUNT with the "unstring" and reference modification with the "string".

As i mentioned earlier, posting the actual code you are using will get you better answers.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Thu Mar 08, 2007 11:27 pm    Post subject:
Reply with quote

dick i think he is mesioning the code given at the post above by agkshirsagar
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: Thu Mar 08, 2007 11:40 pm    Post subject:
Reply with quote

Hello,

Yes, i believe he used that as a model.

I am not sure that is the exact code that is being compiled. Rather than assume, my preference is to see the actual code.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Thu Mar 08, 2007 11:47 pm    Post subject:
Reply with quote

ok , i just make you point to that, i thoght you dont see the code icon_cool.gif
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: Fri Mar 09, 2007 12:32 am    Post subject:
Reply with quote

I saw the posted code.

Often, what winds up in the program being compiled is a modified version of the posted code.

Sometimes that modification is not intentional icon_smile.gif
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Fri Mar 09, 2007 1:41 am    Post subject: Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle
Reply with quote

I got rid of the first problem. Second is still trying.
This is the actual code with output.

01 NAME.
05 L PIC X(30) VALUE ALL '#'.
05 F PIC X(30) VALUE ALL '#'.
05 M PIC X(30) VALUE ALL '#'.
* YOUR FORMAT IS L F M
01 FINAL-NAME PIC X(30).
PROCEDURE DIVISION.

MAIN-PARA.

MOVE 'JOHN*ED*CAUSEY SATTELBERG*' TO WS-NAME.
UNSTRING WS-NAME DELIMITED BY '*' INTO
F,M,L.

DISPLAY 'F:' F.
DISPLAY 'M:' M.
DISPLAY 'L:' L.

STRING
L,'@'
F,'@'
M,'@' DELIMITED BY '#'
INTO FINAL-NAME.
INSPECT FINAL-NAME REPLACING ALL '@' BY ' '.
DISPLAY FINAL-NAME.

O/p:

F:JOHN
M:ED
L:CAUSEY SATTELBERG
CAUSEY SATTELBERG
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Fri Mar 09, 2007 2:22 am    Post subject:
Reply with quote

good thus we got a practical model icon_wink.gif
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Fri Mar 09, 2007 4:01 am    Post subject: Re: Cobol code Firstnm*MI*Lastname to Lastname Firstname Mi
Reply with quote

I think, this cannot be achieved ny String and Inspect verb. bcoz the last name length is dynamic and soem times space some time -. This can be achieved by writing a routine.
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
No new posts IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us