Last month I spoke on translating text, and one of the examples I used was a lowercase to uppercase translation...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
within your RPG program.
This month I would like to address another way to deal with mixed-case text by retrieving the key field and ignoring the case it is currently in.
Say we have a physical file that contains a name and address and we want to store the name in mixed case. Now, when the user selects the name he wants, the system needs to retrieve the requested record ignoring the case.
An example of this would be storing the last name of a person like "Smith" but retrieving the record by using "SMITH".
This can be accomplished by placing an alternate sequence in the DDS of a logical file or a physical file. This is a file-level keyword. Below is how you would define the DDS.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 00010A ALTSEQ(QSYSTRNTBL) 00020A R RCUST PFILE(CUST) 00030A LASTNAME 00040A FIRSTNAME 00050A ADDRESS 00060A CITY 00070A K LASTNAME 00080A K FIRSTNAME
By setting an ALTSEQ, the view of this data will translate the text from lower to upper, so the case is basically ignored. The sort of the sequenced view would place the "SMITH" and "Smith" next to each other. This works very well for report and subfile displays.
When setting up a table, each 2-byte position in the table corresponds to a character. To change the order in which a character is sorted, change its 2-digit value to the same value as the character it should be sorted equal to. IBM has provided QCASE256 table in library QUSRSYS for you. This will do the lowercase to uppercase translation.
This technique is a simple and easy way to translate text without placing additional lines of code within your program. The simpler the code, the easier it is to maintain later.
About the author: John Kohan is a senior programmer analyst at CT Codeworks. He is also an adjunct instructor teaching AS/400 classes at his local state collage. As one of search400's site expert John also participates in our Ask the Expert feature. If you have a question for him, you may submit it.
- The Best Web Links on Development: Tips, tutorials and more.
- Ask your programmer questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our programmer gurus are waiting to answer your technical questions.
- What do you think of this tip? Send us your comments -- good or bad -- at firstname.lastname@example.org