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

Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Thu Mar 08, 2007 8:42 am
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
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
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: 691
Location: Earth

PostPosted: Thu Mar 08, 2007 12:26 pm
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: 127
Location: kerala,india

PostPosted: Thu Mar 08, 2007 1:12 pm
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: 97
Location: India

PostPosted: Thu Mar 08, 2007 6:15 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Mar 08, 2007 9:40 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Mar 08, 2007 10:25 pm
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: 127
Location: kerala,india

PostPosted: Thu Mar 08, 2007 10:59 pm
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

Moderator Emeritus


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

PostPosted: Thu Mar 08, 2007 11:22 pm
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: 127
Location: kerala,india

PostPosted: Thu Mar 08, 2007 11:27 pm
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

Moderator Emeritus


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

PostPosted: Thu Mar 08, 2007 11:40 pm
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: 127
Location: kerala,india

PostPosted: Thu Mar 08, 2007 11:47 pm
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

Moderator Emeritus


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

PostPosted: Fri Mar 09, 2007 12:32 am
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
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: 127
Location: kerala,india

PostPosted: Fri Mar 09, 2007 2:22 am
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
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
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Mar 09, 2007 4:28 am
Reply with quote

The FM states: "One UNSTRING statement can take the place of a series of MOVE statements"
The rules for moving an alphanumeric elementary item are the same as those for the MOVE statement"
You might find this works better.
Code:

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

MAIN-PARA.                                       
    MOVE SPACES TO NAME.     
    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      DELIMITED BY X'4040'
        ', '   DELIMITED BY SIZE 
        F      DELIMITED BY X'4040'
        SPACE  DELIMITED BY SIZE     
        M      DELIMITED BY X'4040'             
        INTO FINAL-NAME.                         
    DISPLAY FINAL-NAME. 

O/p:

F:JOHN                       
M:ED                         
L:CAUSEY SATTELBERG         
CAUSEY SATTELBERG, JOHN ED
So much for
cobolunni wrote:
good thus we got a practical model icon_wink.gif
icon_rolleyes.gif
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: Fri Mar 09, 2007 8:06 am
Reply with quote

By jove, i think he's got it!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 9:18 am
Reply with quote

Thanks to Every body for your valuable inputs, this works.
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: Fri Mar 09, 2007 10:30 am
Reply with quote

Cool icon_cool.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Mar 09, 2007 12:27 pm
Reply with quote

cobolunni wrote:
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


This wont work.
Because after unstring you will get trailing spaces in the F,M,L.
I would suggest one change..
Code:

 ACCEPT WS-NAME.                                   
 INSPECT WS-NAME REPLACING ALL SPACES BY '@'   
 UNSTRING WS-NAME DELIMITED BY '*' INTO           
       F,M,L.                                     

i.e. Replacing spaces by @ immediately after you get the value in your variable. ( I am sure you are not using ACCEPT )

Optimize the code after you get exactly what you wanted icon_biggrin.gif
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compile rexx code with jcl CLIST & REXX 6
Search our Forums:

Back to Top