Thanks in Advance
Ken Stratton
Fort Fairfield, Maine, USA
The _easiest_ way is with the XLATE operation. Here's what you can do:
I 'ABCDEFGHIJKLMNOPQRST- C UC
I 'UVWXYZ'
I 'abcdefghijklmnopqrst- C LC
I 'uvwxyz'
*
*
*
C UC:LC XLATESOURCE TARGET
The above code translates all uppercase letters in field SOURCE to their
lowercase equivalents, placing the result in field TARGET. It doesn't
change any characters except the letters.
For example, consider SOURCE = 'An IBM AS/400'
After the XLATE, TARGET = 'an ibm as/400'
As you can see, the slash (/) was not altered, and neither were the numerals.
-EM
--
Ernie Malaga (muf...@earthlink.net)
Senior Technical Editor
Midrange Computing
>Can someone suggest an easy way to convert uppercase letters to
>lowercase letters or vise-versa. I have seen the examples in the IBM
>RPG reference manuals with the XLATE command, and that works
>great as long as I can tell it which position to begin converting, but
>maybe there is another way... you know, like with ASCII characters...
>the ASCII value for uppercase characters are x number higher than
>lowercase characters? Are things the same with EBCIDIC? If so
>where do I get the EBCIDIC character value for the letters A-Z?
At least three methods can be used:
1. Call the QDXCLATE API and specify a table name. The system includes
a table named QSYSTRNTBL to convert from lower- to uppercase, but the
table for upper- to lowercase translation is not included. You'll have
to create the source and compile it using the CRTTBL command.
2. Specify two constants in your RPG program. One defining all the
uppercase letters, and one for all the lowercase letters. Use the
XLATE operation code to convert.
3. Place the string to be converted in an array and use BITON/BITOFF
to set or clear the bit that decides if it's an upper- or lowercase
character. You will have to test that the character is within the
valid ranges.
For all methods you will have to make sure that there are no packed
decimal data in the string as you don't want to convert them!
The character values are printed in some manuals (including
Programmers Reference Summary if I remember correctly). On previous
releases you could press the Test key on a workstation an display all
characters with hex codes. I think the letter A starts at x'81' and
x'C1', there are some special characters inbetween the letters.
Njål Fisketjøn
FIGU DATA AS
nfis...@figu.no
nfis...@e-mail.com
Kendall F. Stratton III <kfst...@kfsthree.sdi.agate.net> wrote in article
<55bkms$2...@service-2.agate.net>...
> Can someone suggest an easy way to convert uppercase letters to lowercase
letters > or vise-versa
Strangely enough you can use everyones' favorite opcodes BITON & BITOFF to
change from lower case to upper case and visa versa. (I think you were
already barking up this tree :-) In so far as the EBCDIC codes you are
going to have to check one of the manuals on the softcopy for a table.
Just remember that this is not portable to Unix or NT when the ANSI RPG
compilers come out! :-)
Hope this helps. Graeme
ARR is defined as 30 (or whatever size) elements, each 1 long.
The reason you bitof the 2nd bit is that a is hex 81 or 1000 0001 and A is
1100 0001.
Now this is NOT fool proof because it compares hex C1 thru hex E9 and
there are goofball (not anything that is common) in hex CA-CF and hex
DA-DF and things like D0, E0, and E1. So if you are a "purest", then you
would need to compare A-I and J-R and S-Z
However I use the above style routine all the time and those mentioned
possible holes NEVER effect me.
chris
D Upper C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
D Lower C 'abcdefghijklmnopqrstuvwxyz'
C Upper:Lower XLATE InpField OutField
Jon Paris - jo...@vnet.ibm.com - AS/400 AD
'abcdefghijklmnop- C LC
'qrstuvwxyz'
'ABCDEFGHIJKLMNO- C UC
'OPQRSTUVWXYZ'
Then just use the XLATE op code
to convert lower to upper
LC:UC XLATE LCFLD UCFLD
to convert upper to lower
UC:LC XLATE UCFLD LCFLD
Ron
The same applies to RPG III, as suggested. Define to lines of type 'N'
(i.e. constants) and use the XLATE operator. Anything not in the
source constant will be mapped as-is, so you only need to specify the
letters of the alphabet, not every symbol.
I used the above ploy to convert a PC-format file, where the numbers
did not have leading zeros. Just use :
' ':'0' XLATE XYZ XYZ
and everything is hunky-dorey.
Jim
"There's two lanes running down this road, and whichever side you're on...
Accounts for where you want to go, or what you're running from..."
Jim Willsher <will...@sol.co.uk>
I just picked up this message so didn't get the 1st bit.
Anyway, cut out the code below, send to AS/400 and compile.
Please use program in it's entirety. I will have this (and others)
available on my web page sometime (soon?). Note the '+' in column 7
is from a pgm I wrote that 'highlight's comment lines. Anybody
interested?
Regards, Kevin.
H*****************************************************************
H/TITLE Convert Lower to Upper (&vice versa) Case Letters
H D
H*****************************************************************
H*+ P R O G R A M T I T L E A N D R E F E R E N C E S
H*+ - - - - - - - - - - - - - - - - - - - - - - - - - - - -
H*
H*+ Convert Lower to Upper (&vice versa) Case Letters
H*
H*+ RPG PROGRAM - LOWUP - 26.10.93 - VERSION 1.0
H*+ AUTHOR - K Carroll - K D Carroll Ltd
H*+ The Homestead
H*+ Hamurana Road
H*+ RD2 Rotorua
H*+ New Zealand.
H*+ Phone (+64-21) 440 757
H*+ Fax (+64-21) 660 758
H*+ Email ke...@kdc.co.nz
H*+ WWW www.kdc.co.nz
H*
H*+***************************************************************
H*+ C O P Y R I G H T
H*+ - - - - - - - - -
H*
H*+ COPYRIGHT 1993, 1996 K D Carroll Ltd
H*+ The information contained in this program was developed
H*+ by K D Carroll Ltd, which has proprietary rights herein
H*+ and may not be copied or reproduced in any manner whatsoever
H*+ without written consent of K D Carroll Ltd. Information
H*+ contained in this program is subject to change and revision
H*+ by K D Carroll Ltd.
H*
H*+ This program may be used in its entirety. No responsibility
H*+ is accepted for anything! You use it, so you test it 1st!
H*+***************************************************************
H*+ P R O G R A M N A R R A T I V E
H*+ - - - - - - - - - - - - - - - - -
H*
H*+ This program converts a text string from Lower to Upper Case
H*+ (or vice versa). A maximum string length of 256 characters is
H*+ allowed.
H*+ Three (3) parameters are expected.
H*+ 1. MODE - 'U' = Lower to Upper Case.
H*+ - 'L' = Upper to Lower Case.
H*+ 2. LENGTH - Length of String. Lower Limit = 1, Upper = 256
H*+ 3. STRING - String to be processed.
H*
H*+***************************************************************
E*
E*+Input/Output Array
E @IO 256 1
E*+***************************************************************
C*
C*+Mainline
C*+--------
C*
C*+Receive parameters
C *ENTRY PLIST
C PARM MODE 1
C PARM LENGTH 30
C PARM STRING256
C*
C*+Initialise Fields. Exit if String Length out of allowed range
C*+or mode is invalid.
C LENGTH IFGE 1
C LENGTH ANDLE256
C Z-ADDLENGTH #A 30
C ELSE
C GOTO ENDPGM
C*+ ---- ------
C ENDIF
C*
C MODE IFNE 'U'
C MODE ANDNE'L'
C GOTO ENDPGM
C*+ ---- ------
C ENDIF
C*
C Z-ADD1 #B 30
C CLEAR@IO
C MOVEASTRING @IO,#B
C CLEARSTRING
C*
C*+Process Lower to Upper Case Conversion
C SELEC
C MODE WHEQ 'U'
C DO #A #B
C @IO,#B IFGE 'a'
C @IO,#B ANDLE'z'
C TESTB'0' @IO,#B 81
C *IN81 IFEQ *ON
C BITON'1' @IO,#B
C ENDIF
C ENDIF
C ENDDO
C*
C*+Process Upper to Lower Case Conversion
C MODE WHEQ 'L'
C DO #A #B
C @IO,#B IFGE 'A'
C @IO,#B ANDLE'Z'
C TESTB'1' @IO,#B 81
C *IN81 IFEQ *ON
C BITOF'1' @IO,#B
C ENDIF
C ENDIF
C ENDDO
C ENDSL
C*
C*+Clear any remaining characters in the string.
C #A IFLT 256
C MOVEA@IO,#B STRING
C STRING IFNE *BLANK
C CLEARSTRING
C MOVEASTRING @IO,#B
C ENDIF
C ENDIF
C*
C*+Return Converted String
C MOVEA@IO STRING
C*
C*+End Program
C ENDPGM TAG
C*+ ------ ---
C SETON LR
C RETRN
--
+-------------------------------------------------------------+
Kevin Carroll IT Advisor Web Page: http://www.kdc.co.nz
Email: ke...@kdc.co.nz Ph: +64-21-440 757 Fax: +64-21-660 758
K D Carroll Ltd (Information Technology Services) New Zealand
>I only have sample code in RPG IV to hand, but you can do the same
>thing in RPG III - it's a lot simpler than a loop.
>
> D Upper C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
> D Lower C 'abcdefghijklmnopqrstuvwxyz'
>
> C Upper:Lower XLATE InpField OutField
>
>
>Jon Paris - jo...@vnet.ibm.com - AS/400 AD
This will work fine in RPGIV, but I have discovered a severe bug with
the XLATE opcode in RPGIII programs running on 3.6. The problem occurs
under certain circumstances when you are dealing with different length
fields in the XLATE process. Under RPGIV, the shorter fields are
padded out, and the correct response is returned in the result field,
but the padding out does not occur properly in RPGIII programs. Even
RPGIII programs that were working properly under 3.1 began failing
after converting to 3.6, regardless of whether they had been
recompiled under the new release.
We reported this to IBM several weeks ago, and they have yet to get
back to us with a response.
_____________________________________________________________________
"But there must be something more to death than surfing all the time"
- Dar Williams
Why re-invent the wheel when you've got XLATE and IBM supplied API's
that do the same thing faster?
Simple. I wrote it in 1993 and it's still in use.
Also, it's easy to call and get a result back without specifically adding
the necessary code to a pgm. Also derivations that capitilise 1st word
etc.
--
+-------------------------------------------------------------+
Kevin Carroll IT Advisor Web Page: http://www.kdc.co.nz
Mailto: ke...@kdc.co.nz Ph: +64-21-440 757 Fax: +64-21-660 758
In EBCDIC, subtract 64 from the uppercase letter to get lowercase. You
can't have 1-byte binary fields in RPG, so you'll have to move the
byte into a 2-byte binary field, with the hi-order byte full of binary
zeros, then move it back to a 1-byte field after the subtraction.
See TechTalk in the November 93 issue of MC.
XLATE is a lot easier to use.
Kendall F. Stratton III <kfst...@kfsthree.sdi.agate.net> wrote:
>Can someone suggest an easy way to convert uppercase letters to lowercase letters or vise-versa.
> I have seen the examples in the IBM RPG reference manuals with the XLATE command, and that
> works great as long as I can tell it which position to begin converting, but maybe there is another way...
> you know, like with ASCII characters... the ASCII value for uppercase characters are x number higher
>than lowercase characters? Are things the same with EBCIDIC? If so where do I get the EBCIDIC
>character value for the letters A-Z?
>Thanks in Advance
>Ken Stratton
>Fort Fairfield, Maine, USA
=======================================================
Ted Holt
ted...@tsixroads.com
ho...@midrangecomputing.com
--------------------------------------------------------
Why fry your brain doing drugs? TV is legal and cheaper!
========================================================
Hello,
An easier alternative to the binary-add-or-subtract-64 is simply to use
the biton and bitof opcodes to toggle bit 1 on or off, as in
BITON '1' @BTYE
But you must first check to be sure its a character between A and Z or
you will be changing your blanks and other characters to who knows what.
Do not use range chacking for this test, as in
@BYTE IFGE 'A'
@BYTE ANDLE 'Z'
because certain little-used characters fall in between A and Z in EBCDIC.
Instead, set up a named constant that contains the 26 letters of the
alphabet in upper or lower case and use the CHECK opcode to see if the
character you are dealing with is one you want to convert.
Good luck,
Pete Whitstone
Weasel Software
> wouldn't it be easier to just use qclxlate and send the data through
>the translation table?
Yes, ANY METHOD is better than subtracting 64 from uppercase to get
lowercase.
If you have questions, post a message or send an email
Thanks
Vincent