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 ...
LATEST COMMENTS
MC Press Online