View previous topic :: View next topic
|
Author |
Message |
Ajay Dwivedi
New User
Joined: 20 Jan 2008 Posts: 3 Location: India
|
|
|
|
Hi All,
I am looking for a cobol code. Inspect should probably work but I am not getting exact logic.
I have a requirement to format Name in title case.
Eg : smith - john / smith-john should output as Smith - John/Smith-John respectively.
Could anyone advise please?[/code] |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You need to work out how you would do it manually, then do that in a loop.
I'd REDEFINES with OCCURS, or use a subordinate OCCURS, but many people would lose clarity by using reference-modification.
Work out the logic first.
INSPECT is to going to be any real use to you.
There's intrinsic functions which will do the case change you'll need. |
|
Back to top |
|
|
Ajay Dwivedi
New User
Joined: 20 Jan 2008 Posts: 3 Location: India
|
|
|
|
Thanks Bill,
I am using
MOVE FUNCTION LOWER-CASE<string 1> TO <string 2>
INSPECT <string 2>(1:1) CONVERTING lower-case TO upper-case
Above code will work as:
I/p - smith-john
O/p - Smith-john
I need o/p as - Smith-John, and if there's a space around hyphen (-) it should come as :
Smith - John
Will give |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
You need to identify the position of '-' in your string.
And you can use INSPECT TALLYING to get the number of characters before '-'.
Once you get the position it should be easier.
INSPECT String-1 TALLYING Ws-Tally-Counter FOR CHARACTERS BEFORE INITIAL '-'
I think this should work for you.
. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Instead, Why don't you loop each byte of the string in loop and convert the letter after '/' or '-' to upper case and move rest all lower case?
Ah, Bill already said so. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Capitalising names reveals lots of interesting things. Like O'Neil. McDonald. Jean-Paul Jorge-Ringo. M Robert Tinsell. Your SMITH_-_JOHN could then also be SMITH__-_JOHN, SMITH__-JOHN and variations.
How good is your data? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Don't forget me |
|
Back to top |
|
|
Ajay Dwivedi
New User
Joined: 20 Jan 2008 Posts: 3 Location: India
|
|
|
|
Thanks everyone for your suggestions!
Firstly, I have converted the string to all lower-case, and first character to uppercase.Then performed a loop and converted each character after <space> or '-' to upper case.
I/p = smItH - jOhN
Setting all to lower case = smith - john
Converting first letter to uppercase = Smith - john
In a loop, converting each character after '-' or <space> to uppercase = Smith - John
O'Neil, McDonald - wud appear as O'neil, Mcdonald resp.
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Quote: |
Firstly, I have converted the string to all lower-case, and first character to uppercase.Then performed a loop and converted each character after <space> or '-' to upper case. |
Why? and due to this you have now below problem ( D-->d).
Quote: |
O'Neil, McDonald - wud appear as O'neil, Mcdonald resp. |
I suggest check the case belore converting all to the lower case and as other's said you should be knowing all the probable special characters that will be part of your string, get that from someonw who knows and then code otherwise it will break now and later.
Finally, if you could have a choice of DB2 then you should make this COBOL-DB2 program and make everyone's life easier . |
|
Back to top |
|
|
|