TechTalk: Using Variables With OPNQRYF

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

Q. I need some help with the OPNQRYF command using the keyword %RANGE. The problem I am having is moving values into variables when I do the QRYSLT. I have read your articles titled, "That Darn OPNQRYF..." (October 1990) and "More Tricks With the OPNQRYF," (November 1990). I get the CL to compile but it blows up when I run it. It runs okay and produces my report if I use constants defined in 2a.

Q. I need some help with the OPNQRYF command using the keyword %RANGE. The problem I am having is moving values into variables when I do the QRYSLT. I have read your articles titled, "That Darn OPNQRYF..." (October 1990) and "More Tricks With the OPNQRYF," (November 1990). I get the CL to compile but it blows up when I run it. It runs okay and produces my report if I use constants defined in Figure 2a.

How would you do the OPNQRYF using the keyword %RANGE based on variables as in 2b (page 63)?

How would you do the OPNQRYF using the keyword %RANGE based on variables as in Figure 2b (page 63)?

I appreciate any help.

A. In response to your question about using variables with OPNQRYF, here is a possible solution. This solution has already been presented in the article, "That Darn OPNQRYF..."; however, maybe seeing it applied to your code will help you to understand how it works.

Create a character variable 512 bytes long and call it &QRYSLT. Construct the QRYSLT statement by dividing it up into simple pieces and putting it back together into the &QRYSLT variable. Make sure all variables that make up the pieces are character or converted to character before the concatenation. (In your program all variables are already character, but this would probably be the exception.) Using your code, the code would look like 2c (page 63).

Create a character variable 512 bytes long and call it &QRYSLT. Construct the QRYSLT statement by dividing it up into simple pieces and putting it back together into the &QRYSLT variable. Make sure all variables that make up the pieces are character or converted to character before the concatenation. (In your program all variables are already character, but this would probably be the exception.) Using your code, the code would look like Figure 2c (page 63).

It's really quite simple. Just remember that only literals can be inside apostrophes, variables cannot.

I encourage you to learn this technique because it can be used to make the most complicated OPNQRYF using variables easy to handle.


TechTalk: Using Variables With OPNQRYF

Figure 2A Sample OPNQRYF using constants

 Figure 2a: Sample OPNQRYF Using Constants OVRDBF FILE(SRSOMF01) SHARE(*YES) OPNQRYF FILE((SRSOMF01)) QRYSLT('SMEXDT = %RANGE(920131 920131) & SMCONR = "08"') CALL PGM(SR00788RX) /* RPG to write selected records + based on policy expiration date */ CLOF OPIND(SRSOMF01) 
TechTalk: Using Variables With OPNQRYF

Figure 2B User's attempt to set up variables for OPNQRYF

 Figure 2b: Users Attempt to Set Up Variables for OPNQRYF DCL VAR(&CO#) TYPE(*CHAR) LEN(2) /* Company number */ DCL VAR(&BGDTE) TYPE(*CHAR) LEN(6) /* Beginning date */ DCL VAR(&ENDTE) TYPE (*CHAR) LEN(6) /* Ending date */ CALL PGM(SR00788R) /* Screen to allow user to enter values */ CHGVAR VAR(&CO#) VALUE(%SST(*LDA 1 2)) CHGVAR VAR(&BGDTE) VALUE(%SST(*LDA 4 6)) CHGVAR VAR(&ENDTE) VALUE(%SST(*LDA 11 6)) 
TechTalk: Using Variables With OPNQRYF

Figure 2C Sample OPNQRYF using variables

 Figure 2c: Sample OPNQRYF Using Variables DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(512) . . Your Code . CHGVAR VAR(&QRYSLT) VALUE('SMEXDT = %RANGE(' *CAT &BGDTE) CHGVAR VAR(&QRYSLT) VALUE(&QRYSLT *BCAT &ENDTE *CAT ')') CHGVAR VAR(&QRYSLT) VALUE(&QRYSLT *BCAT '& SMCONR =') CHGVAR VAR(&QRYSLT) VALUE(&QRYSLT *BCAT '"' *CAT &CO# *CAT + '"') OVRDBF ... OPNQRYF FILE ((SRSOMF01)) QRYSLT(&QRYSLT) CALL ... CLOF ... 
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: