TechTalk: QRYSLT With a Template

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

Building the QRYSLT parameter string of an OPNQRYF command is tricky business. You may be sick and tired of using so many concatenation operators (*CAT, *BCAT and *TCAT) and so many quotes, double quotes, quadruple quotes, etc. Further, when you use numeric variables, you must declare two variables: one in numeric format, the other in character format, since you cannot use the concatenation operators on numeric variables.

Take heart. Here's a technique you can use to do away with all this baggage, while improving readability of your CL programs. The technique consists of defining the desired-or final-QRYSLT string using a DCL statement, including placeholder characters for the variable values, and then "plugging" in the variables at the correct positions using the %SST (substring) function. In short, you'll be building a template.

Consider the example provided in 2. The CL program receives two parameters: &STATE (character) and &ZIP (decimal). The two CHGVAR commands plug the values of &STATE and &ZIP into the QRYSLT template, which is contained in variable &SEL. Then it's just a matter of running the OPNQRYF command.

Consider the example provided in Figure 2. The CL program receives two parameters: &STATE (character) and &ZIP (decimal). The two CHGVAR commands plug the values of &STATE and &ZIP into the QRYSLT template, which is contained in variable &SEL. Then it's just a matter of running the OPNQRYF command.

Editor's Note: This technique will work fine as long as the variables are fixed-length. Don't try to use this with variable-length variables.


TechTalk: QRYSLT With a Template

Figure 2 Sample QRYSLT template

 Figure 2: Sample QRYSLT Template DCL VAR(&STATE) TYPE(*CHAR) LEN(2) DCL VAR(&ZIP) TYPE(*DEC) LEN(5 0) DCL VAR(&SEL) TYPE(*CHAR) LEN(33) + VALUE('STATE *EQ "xx" *AND ZIP *EQ nnnnn') + /* Template: .... ....1.... ....2.... ....3... */ CHGVAR VAR(%SST(&SEL 12 2)) VALUE(&STATE) CHGVAR VAR(%SST(&SEL 29 5)) VALUE(&ZIP) OVRDBF ... OPNQRYF FILE((...)) QRYSLT(&SEL) KEYFLD((...)) ENDPGM 
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: