View previous topic :: View next topic
|
Author |
Message |
ranjith_gowdhaman
New User
Joined: 14 Dec 2005 Posts: 4 Location: india
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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
a stupid google search with "cobol tolower toupper" returned quite a few useful links |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
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 |
|
|
Suresh Shankarakrishnan
New User
Joined: 11 Jul 2008 Posts: 42 Location: USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
Using HEX notation eliminates this possible oversight.
IMHO, newer methods don't necessarily translate to better methods....
Bill |
|
Back to top |
|
|
Chirantan Banerjee
New User
Joined: 08 Oct 2009 Posts: 12 Location: Kolkata, India
|
|
|
|
Quote: |
I know, that never happens.
|
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 |
|
|
|