View previous topic :: View next topic
|
Author |
Message |
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
yes the delimiter is '*'.
Thanks |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
yes you can optimise the code using count-in and pointer clause in first unstring |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
The above code will work fine. |
|
Back to top |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
dick i think he is mesioning the code given at the post above by agkshirsagar |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
ok , i just make you point to that, i thoght you dont see the code |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
good thus we got a practical model |
|
Back to top |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
By jove, i think he's got it! |
|
Back to top |
|
|
vishwaroopa
New User
Joined: 08 Mar 2007 Posts: 8 Location: US
|
|
|
|
Thanks to Every body for your valuable inputs, this works. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Cool |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
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 |
|
Back to top |
|
|
|