TechTalk: Using SETLL to Search Mixed-case Strings

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: