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
 

 

Converting fields from lower case to upper case

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
asagar

New User


Joined: 11 Jul 2012
Posts: 10
Location: Honduras

PostPosted: Tue Sep 18, 2012 7:48 pm    Post subject: Converting fields from lower case to upper case
Reply with quote

I am writing a sanity check program, which requires converting some fields from lower case to upper case. I understand that using the 'Inspect' verb is an option, are there any other ways of doing this too ?
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Tue Sep 18, 2012 7:50 pm    Post subject:
Reply with quote

Enterprise COBOL supports the intrinsic function UPPER-CASE.
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Tue Sep 18, 2012 7:51 pm    Post subject:
Reply with quote

You're right, that is an option.

Another one is to use the Enterprise COBOL intrinsic function called "Upper-Case". It goes something like this:

Compute ws-upper = FUNCTION UPPER-CASE(ws-lower)
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 18, 2012 7:52 pm    Post subject:
Reply with quote

Funtion UPPER-CASE
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 641
Location: Whitby, ON, Canada

PostPosted: Tue Sep 18, 2012 7:59 pm    Post subject:
Reply with quote

Hint: check out the list of Intrinsic functions in the Cobol Language Reference.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Tue Sep 18, 2012 8:18 pm    Post subject: Reply to: Conersion from lower case to upper case
Reply with quote

Yes, there are other ways. I feel somewhat "beaten" on the obvious suggestion :-)

What do you mean by a "sanity check program", just out of interest, and how does this relate to it?
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: Tue Sep 18, 2012 8:39 pm    Post subject: Reply to: Conersion from lower case to upper case
Reply with quote

I'm partial to the INSPECT CONVERTING with literals. The compiler generates an in-line TR instruction, whereas, with the FUNCTION's, the compiler generates a BALR to a run-time routine. FUNCTION's were not introduced until COBOL/370, about 20 years ago.

One thing I will say when using the INSPECT, I always coded the lower-case letters using hex-representation (IE: X'81' as opposed to 'a'), instead of taking the chance that someone (like me) brings the code up in CAPS ON mode and accidentally hits the line where the lower-case letters are coded and converts them to upper-case. icon_rolleyes.gif
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: Tue Sep 18, 2012 10:14 pm    Post subject: Reply to: Conersion from lower case to upper case
Reply with quote

It would be great if COBOL had an MVZ-like command, where you can move 4-Bit zone 'C' values to the zone of each byte of an existing alphabetic string, which performs the upper-case change. Maximum length of the target string, from an Assembler point-of-view, is 256.

An "OC" (OR-character) like-command would work just as well using SPACES (B'11000001') as the mask, which would turn-on the second-bit (from the left), converting a lower-case 'a' (B'10000001') to an upper-case 'A' (B'11000001'). Again, maximum target-string length of 256.

When using either of these methods, the content of the string must be guaranteed to have only lower-case letters or "Unpredictable results may occur" and you know what that means. icon_wink.gif

As an exercise, try moving each byte to the low-order byte of a redefined halfword, PIC 9(04) COMP, (cleared to X'00's), add 64 to the halfword and move the halfword low-order byte back to the string. Same result, horrible overhead.... icon_rolleyes.gif
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: Tue Sep 18, 2012 10:32 pm    Post subject: Reply to: Conersion from lower case to upper case
Reply with quote

A correction to my previous post (must be "out of my mind" Tuesday), regarding the "OC", a SPACE is a B'01000000'. icon_rolleyes.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Tue Sep 18, 2012 10:51 pm    Post subject: Reply to: Conersion from lower case to upper case
Reply with quote

Even redefine the field as several as-large-as-you-can binary and a last-one-to-make-up-the-length binary, then add specific values (I've not calculated them :-) ).

Again, only good-to-go if field exclusively contains lower-case letters. Even space would be garbled.

Similar is possible for ASCII/EBCDIC conversion, although there the space goes nicely.
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: Wed Sep 19, 2012 2:04 am    Post subject: Reply to: Conversion from lower case to upper case
Reply with quote

Bill,

Or, divide the length of the string by 4 and get a remainder. Then you could add a fullword of X'40404040' (1077952576) to 4-Bytes at a time in an in-line PERFORM. If the compiler doesn't support COMP-5, then TRUNC(BIN) must be specified.

After coming out of the PERFORM (if the length of the string was less than 4, then you would have never executed the PERFORM), check for a remainder from the divide and if found, take care of the last 1-3 bytes and you're done.
Back to top
View user's profile Send private message
asagar

New User


Joined: 11 Jul 2012
Posts: 10
Location: Honduras

PostPosted: Wed Sep 19, 2012 3:45 pm    Post subject:
Reply with quote

I would use the COBOL intrinsic function UPPER-CASE.

Thank you so much for your replies.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Wed Sep 19, 2012 3:55 pm    Post subject: Reply to: Conversion from lower case to upper case
Reply with quote

Did you read Bill's first reply? If you have lots to do, it would be worth doing a comparison.

If not many, the FUNCTION approach is easier to understand.

Perhaps for a "sanity check" you should have chosen one of the tortuous solutions :-)
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: Wed Sep 19, 2012 6:37 pm    Post subject: Reply to: Conversion from lower case to upper case
Reply with quote

Bill,

Jim Moore (a programmer's programmer) would agree and also go with the INSPECT with LITERALS.

Regards,
Back to top
View user's profile Send private message
Michael Simpson

New User


Joined: 27 Sep 2012
Posts: 6
Location: Sweden

PostPosted: Sat Sep 29, 2012 2:23 pm    Post subject: One other aspect ...
Reply with quote

what about special characters in all your solutions (I'm thinking of Swedish åäö to ÅÄÖ).

Not being at work, I seem to remember that the upper-case won't work with these characters. (Maybe you can use the special-names clause to get it to work ???)
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7235

PostPosted: Sat Sep 29, 2012 3:32 pm    Post subject: Reply to: Conversion from lower case to upper case
Reply with quote

Michael,

Welcome to the forum.

Whether it can be considered a major oversight or not, I suspect that the vast majority of systems outside Scandanavia pay little heed to Scandanavian characters.

Having said that, the INSPECT ... CONVERTING with literals in hex (X'...'), suggested by the other Bill, would be applicable to any single byte value. For a multi-byte value, INSPECT ... REPLACING could be suitable.
Back to top
View user's profile Send private message
Michael Simpson

New User


Joined: 27 Sep 2012
Posts: 6
Location: Sweden

PostPosted: Sat Sep 29, 2012 6:35 pm    Post subject: Thank you Bill
Reply with quote

I agree with the scandinavian comment.

My point was more that this is probably just as relevant with special french, spanish, german etc characters sets as well
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
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts Converting multiple VB files to FB fi... Viswanath Reddy JCL & VSAM 6 Mon Aug 08, 2016 11:49 pm
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
No new posts Converting EBCDIC to Unicode (TimeStamp) muralikrishnan_new COBOL Programming 2 Mon Jul 25, 2016 10:42 pm
No new posts Need Help to Define 36 Input Fields (... satish.ms10 CLIST & REXX 2 Sat May 07, 2016 3:08 pm


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