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

Converting fields from lower case to upper case


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8700
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 18, 2012 7:50 pm
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
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
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: 765
Location: Whitby, ON, Canada

PostPosted: Tue Sep 18, 2012 7:59 pm
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

Moderator Emeritus


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

PostPosted: Tue Sep 18, 2012 8:18 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Sep 18, 2012 8:39 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Sep 18, 2012 10:14 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Sep 18, 2012 10:32 pm
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

Moderator Emeritus


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

PostPosted: Tue Sep 18, 2012 10:51 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 19, 2012 2:04 am
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
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

Moderator Emeritus


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

PostPosted: Wed Sep 19, 2012 3:55 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 19, 2012 6:37 pm
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
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

Moderator Emeritus


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

PostPosted: Sat Sep 29, 2012 3:32 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Pull data using date difference betwe... DB2 6
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Zunit Test case editor error Testing & Performance 4
No new posts Converting fixed length file to excel... IBM Tools 7
Search our Forums:

Back to Top