Q: I have an RPG program in which I use a key as my search argument to set lower limits (SETLL) to a file based on user input. I then do a read to load my records into a subfile. How can I make the SETLL case insensitive? For example, a user may key in the word "LAB," but this word exists as "Lab" or "lab" in my file. I want to be able to get a hit on the word, regardless of whether it's uppercase or lowercase. Can you help me?
A: One way to resolve this problem is to create a logical file that translates a mixed-case field to uppercase. You can accomplish this by using the rename (RENAME) and translation table (TRNTBL) keywords.1 and 2 show an example of how to use these keywords. 1 shows the DDS code for physical file CASEPF. This file contains a single field called MIXED which is used to store mixed-case data. 2 shows the code for logical file CASELF. This file contains the same MIXED field from the physical file, plus a translated uppercase version called UPPER.
A: One way to resolve this problem is to create a logical file that translates a mixed-case field to uppercase. You can accomplish this by using the rename (RENAME) and translation table (TRNTBL) keywords. Figures 1 and 2 show an example of how to use these keywords. Figure 1 shows the DDS code for physical file CASEPF. This file contains a single field called MIXED which is used to store mixed-case data. Figure 2 shows the code for logical file CASELF. This file contains the same MIXED field from the physical file, plus a translated uppercase version called UPPER.
The RENAME keyword allows you to map one physical file field to two or more logical file fields. In this case the physical file field, MIXED, is mapped to both MIXED and UPPER in the logical file. The TRNTBL keyword lets you specify the name of a translation table used by the logical file when accessing data in the physical file.
The translation table QSYSTRNTBL translates the mixed-case data in the field MIXED to upper-case data in the field UPPER. Since the logical file is indexed on the UPPER field, your RPG program can set lower limits with the value "LAB" and begin reading records where the MIXED field contains values such as "Lab" or "lab." Using this technique, you can load your subfile with mixed data requested by the user, while internally taking advantage of the index built over the uppercase version of the data.
TechTalk: Using SETLL to Search Mixed-case Strings
Figure 1 Physical File CASEPF
*=============================================================== * To compile: * * CRTPF FILE(XXX/CASEPF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A R CASEPFR A MIXED 10 A K MIXED
TechTalk: Using SETLL to Search Mixed-case Strings
Figure 2 Logical File CASELF
*=============================================================== * To compile: * * CRTLF FILE(XXX/CASEPF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A R CASELFR PFILE(CASEPF) A MIXED A UPPER I RENAME(MIXED) A TRNTBL(QSYSTRNTBL) A K UPPER
LATEST COMMENTS
MC Press Online