TechTalk: OPNQRYF Templates

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

OPNQRYF Templates

As an OPNQRYF beginner, I stumbled along making the usual mistakes, getting acquainted with error message CPD3129 ("Missing operand on expression...") and often getting lost in quotes and *BCATs. However, I have since written a number of CL programs that use the OPNQRYF command and now use the following technique:

1. I declare a &QRYSLT variable, giving it an initial value that exactly matches what I'll need in the QRYSLT parameter of the OPNQRYF command. In this initial value, I use X's to substitute any character values and 9's to substitute any numeric values.

2. Then I use %SST in a CHGVAR command to replace the X's and 9's with the actual values I require in my QRYSLT expression. See 3. In the example illustrated in 3, the user is expected to give &STATE a two- character value and &ZIP a five-digit value-which the program receives as parameters. When the CHGVAR commands are executed, the computer "sees" the &QRYSLT variable as shown in 4.

2. Then I use %SST in a CHGVAR command to replace the X's and 9's with the actual values I require in my QRYSLT expression. See Figure 3. In the example illustrated in Figure 3, the user is expected to give &STATE a two- character value and &ZIP a five-digit value-which the program receives as parameters. When the CHGVAR commands are executed, the computer "sees" the &QRYSLT variable as shown in Figure 4.

Notice the placement of the comment containing a scale in 3. This eliminates the tedious counting of characters to determine where, along &QRYSLT, to substitute the actual values. This method also eliminates the need to use concatenation operators and significantly reduces the number and placement of quotes. The important thing to remember is that if the variable part of the string is alphanumeric, enclose it in double quotes. It's easier to use one double quote character (") than to use the single quote (') twice. If you do use the single quote characters, the start position of the substitution variable will actually be one less than indicated for every pair of quotes encountered reading the template statement from left to right. In my example I kept things simple and used the one double quote around my character literal. 3 illustrates this.

Notice the placement of the comment containing a scale in Figure 3. This eliminates the tedious counting of characters to determine where, along &QRYSLT, to substitute the actual values. This method also eliminates the need to use concatenation operators and significantly reduces the number and placement of quotes. The important thing to remember is that if the variable part of the string is alphanumeric, enclose it in double quotes. It's easier to use one double quote character (") than to use the single quote (') twice. If you do use the single quote characters, the start position of the substitution variable will actually be one less than indicated for every pair of quotes encountered reading the template statement from left to right. In my example I kept things simple and used the one double quote around my character literal. Figure 3 illustrates this.

- Susan Berrey


TechTalk: OPNQRYF Templates

Figure 3 Coding QRYSLT With Templates

 PGM PARM(&STATE &ZIP) DCL VAR(&STATE) TYPE(*CHAR) LEN(2) DCL VAR(&ZIP) TYPE(*DEC) LEN(5 0) DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(512) + /* ....+... 1 ...+... 2 ...+... 3 ...+ */ + VALUE('STATE *EQ "XX" *OR ZIP *EQ 99999') CHGVAR VAR(%SST(&QRYSLT 12 2)) VALUE(&STATE) CHGVAR VAR(%SST(&QRYSLT 28 5)) VALUE(&ZIP) OPNQRYF FILE((CUSTOMER)) QRYSLT(&QRYSLT) ENDPGM 
TechTalk: OPNQRYF Templates

Figure 4 QRYSLT Value After Substitutions

 /* ....+... 1 ...+... 2 ...+... 3 ...+ */ QRYSLT('STATE *EQ "CA" *OR ZIP *EQ 92008') 
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: