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

Using Inspect in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ajay Dwivedi

New User


Joined: 20 Jan 2008
Posts: 3
Location: India

PostPosted: Sat Sep 26, 2015 11:33 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Sep 26, 2015 11:48 pm
Reply with quote

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
View user's profile Send private message
Ajay Dwivedi

New User


Joined: 20 Jan 2008
Posts: 3
Location: India

PostPosted: Sun Sep 27, 2015 10:08 am
Reply with quote

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
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Sun Sep 27, 2015 10:31 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Mon Sep 28, 2015 7:29 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 28, 2015 8:54 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Sep 28, 2015 10:20 pm
Reply with quote

Don't forget me icon_lol.gif
Back to top
View user's profile Send private message
Ajay Dwivedi

New User


Joined: 20 Jan 2008
Posts: 3
Location: India

PostPosted: Tue Sep 29, 2015 7:33 am
Reply with quote

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.
icon_idea.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Tue Sep 29, 2015 7:27 pm
Reply with quote

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 icon_confused.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

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top