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

Convert from UPPER CASE to LOWER CASE


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

New User


Joined: 14 Dec 2005
Posts: 4
Location: india

PostPosted: Sun Jan 31, 2010 8:45 pm
Reply with quote

As I saw in Working with EBCDIC values
Quote:
Move the byte to a COMP halfwd (low-ord byte). Add 64 and it's now upper case.


Can anyone explain with code on how to convert the content of file from Upper to lower case and vice versa.

Ran.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Jan 31, 2010 9:05 pm
Reply with quote

Quote:
can do it in C by changin the corresponding ASCII values

bad practice... which prevents portability
are You aware that c/c++ libraries have platform independent
functions for such a task?? tolower and toupper

also did You check the cobol documentation for ..
intrinsic functions LOWER-CASE and UPPER-CASE
or if You prefer a RYO solution use INSPECT as follows
INSPECT string1 CONVERTING
"ABCDEFGHIJKLMNOPQRSTUVWXYZ” TO “abcdefghijklmnopqrstuvwxyz"

as usual is faster to ask than do a bit of googling and forumsearching icon_evil.gif
a stupid google search with "cobol tolower toupper" returned quite a few useful links
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: Sun Jan 31, 2010 9:53 pm
Reply with quote

ADD 64 (a poor man's OR) and SUBTRACT 64 (a poor man's AND). This will work on any IBM Mainframe COBOL Version/Release. I'm guilty of using this before the introduction of COBOL II. icon_redface.gif

The INSPECT CONVERTING (as provided above, using literals) will save you a CALL (under the covers) to a COBOL Run-Time routine and was introduced with VS/COBOL II and is upward compatible.

For the Intrinsic Functions, your COBOL Version/Release must be a minimum of COBOL/370 and is also upward compatible. However, their use causes a CALL to a COBOL Run-Time routine.

If you're on OS/VS COBOL, you could use TRANSFORM (ANSI 74) or EXAMINE (ANSI 68), but neither are upward compatible.

YMMV....

Bill
Back to top
View user's profile Send private message
Suresh Shankarakrishnan

New User


Joined: 11 Jul 2008
Posts: 42
Location: USA

PostPosted: Wed Feb 17, 2010 11:36 pm
Reply with quote

To convert to upper case, use

MOVE FUNCTION UPPER-CASE(EMP-LAST-NAME)
TO EMP-LAST-NAME

To convert to lower case, use

MOVE FUNCTION LOWER-CASE(EMP-LAST-NAME)
TO EMP-LAST-NAME


cobol (as well as COBOL) don't care if half the program is in uppercase and the other half in lowercase.
It may be important in the VALUE clauses and in literals (because 'y' is different from 'Y' for example).

When you edit a program, the editor will detect if there are lowercase characters in the file.
It will set the CAPS on or off depending on that.
You can change that default by entering CAPS ON or CAPS OFF in the command line.

If it is CAPS OFF, text will be left as you type it: upper or lower.
If it is CAPS ON, everything you type will be upper-cased. If you modify a line with lowercase, the whole line will be upper-cased.
I have never seen the editor changing from uppercase to lowercase on its own.

You can use UC and LC in the prefix area to convert a whole line.
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: Thu Feb 18, 2010 3:42 am
Reply with quote

I still believe that Enrico's INSPECT CONVERTING with literals is a more efficient method, as the compiler will generate a translate-table and an in-line TR instruction, without incurring a BALR to a COBOL run-time routine, as in the case of the INTRINSIC FUNCTIONs.

The only thing I would do different is to specify the lower-case letters using HEX notation (IE: X'81' through X'89' are lower-case 'a' through 'i').

If someone brings up the source and turns on upper case translation and accidentally hits the line with the lower-case letters, then they become upper-case if the source is then saved.

I know, that never happens. icon_eek.gif

Using HEX notation eliminates this possible oversight.

IMHO, newer methods don't necessarily translate to better methods.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
Chirantan Banerjee

New User


Joined: 08 Oct 2009
Posts: 12
Location: Kolkata, India

PostPosted: Thu Feb 18, 2010 6:04 pm
Reply with quote

Quote:

I know, that never happens. icon_eek.gif


Well Bill, it does happen - a few idiots like myself have the habit of turning CAPS ON profile while coding in COBOL.

..... And it may not sound quite believable but there are a few shops (at least I know of one) which DO NOT ALLOW lowercase letters in their COBOL source code as a programming standard altough the data the programs deal with may contain lowercase characters. In these cases it becomes mandatory to use the HEX notations though it means compromising readability of the code.
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts convert file from VB to FB and use tr... DFSORT/ICETOOL 8
Search our Forums:

Back to Top