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
 

 

Using Inspect in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Using Inspect in cobol
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Sat Sep 26, 2015 11:48 pm    Post subject: Reply to: Inspect in cobol
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    Post subject:
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: 331
Location: USA

PostPosted: Sun Sep 27, 2015 10:31 pm    Post subject: Reply to: Inspect in cobol
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Mon Sep 28, 2015 7:29 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Sep 28, 2015 8:54 pm    Post subject: Reply to: Inspect in cobol
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Sep 28, 2015 10:20 pm    Post subject: Reply to: Inspect in cobol
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    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Tue Sep 29, 2015 7:27 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
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
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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