Translating a File to Uppercase
From: Mark Wheeler To: All
I need to translate the lowercase characters in a physical file to uppercase characters. I would prefer to do this within CL. I am conversant with the translation that occurs within the Copy To PC Document (CPYTOPCD) and Copy From PC Document (CPYFRMPCD) commands and I think that I could use these commands and the table QSYS/QSYSTRNTBL to accomplish my goal. Yet, I would prefer a CL command that would perform the translation without moving the data to a shared folder. Does one exist? REXX has a translate function; should I pursue it? Where does one look in the IBM documentation to have tables (object *TBL) explained? I don't want to write an RPG or COBOL program to do this if it can be avoided. Any thoughts?
From: Ernie Malaga To: Mark Wheeler
I'd stay away from REXX in this case. REXX doesn't recognize external file definitions-it treats the entire record as a single variable. If the record contains packed decimal or binary fields, there's the chance of having a combination of numbers look like a lowercase letter, which REXX would then dutifully convert to uppercase, producing all sorts of decimal data errors later.
For example, the lowercase letter 'a' is X'81', which can appear in a packed decimal field. Suppose you have a (5 0) decimal field which contains the number 2810. This number occupies 3 bytes: X'02', X'81' and X'0F'. The middle byte looks like an 'a', and thus would be converted to an uppercase 'A', which is X'C1'. Your decimal field would then contain 2C10, which is an invalid decimal number. The next time you read this file, you'd get a decimal data error.
I suspect the same thing could happen if you use CPYTOPCD and CPYFRMPCD, but I really don't know. Try it out on a test file before you make the switch.
I don't know how you can avoid using RPG or COBOL. CL can only read records- there's no write operation. If there were, you could use the Receive File (RCVF) command to read a record and then use a call to QDCXLATE to translate lowercase to uppercase (using translation table QSYSTRNTBL) on all alphanumeric fields, followed by a write operation. Since there is no write operation, this avenue is out.
I'd advise you to use RPG or COBOL. The right tool for the right job, as it's been pointed out time after time on this BBS. RPG, for example, has the XLATE op code; I'm sure there's something you can use in COBOL.
LATEST COMMENTS
MC Press Online