Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Convert from UPPER CASE to LOWER CASE

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Convert from UPPER CASE to LOWER CASE
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10308
Location: italy

PostPosted: Sun Jan 31, 2010 9:05 pm    Post subject: Reply to: Working with EBCDIC values
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Sun Jan 31, 2010 9:53 pm    Post subject: Reply to: Convert from Upper to lower case
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    Post subject:
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Thu Feb 18, 2010 3:42 am    Post subject: Reply to: Convert from Upper to lower case
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    Post subject: Re: Reply to: Convert from Upper to lower case
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    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 Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts RFE: DB2 support for mixed case names. Pedro DB2 0 Tue Jul 04, 2017 1:32 am
No new posts Convert CLIST to REXX cvnlynn CLIST & REXX 12 Tue Jun 27, 2017 2:06 am
No new posts Convert current to hex value gopurs DFSORT/ICETOOL 4 Wed Feb 15, 2017 5:40 am
No new posts VALIDATE NULL VALUE IN DB2 CASE STATE... useit DB2 5 Thu Feb 09, 2017 4:34 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us