Passing Parameters to a Query

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

Everybody knows that you can pass parameters to a Query Management query. Not everybody knows that you can do the same with a Query/400 query (object type *QRYDFN). It is very easy to set up. 2 shows you an example of the Select Records panel in which variables are used to receive parameters. (The colon is very important. It indicates a dependent value. The variable name following the colon can be any name you want.)

Everybody knows that you can pass parameters to a Query Management query. Not everybody knows that you can do the same with a Query/400 query (object type *QRYDFN). It is very easy to set up. Figure 2 shows you an example of the Select Records panel in which variables are used to receive parameters. (The colon is very important. It indicates a dependent value. The variable name following the colon can be any name you want.)

After setting up the parameters, press Enter to obtain a screen similar to 3. Just supply a name for a "dummy" query or file; it does not have to exist and is not used in this example.

After setting up the parameters, press Enter to obtain a screen similar to Figure 3. Just supply a name for a "dummy" query or file; it does not have to exist and is not used in this example.

To run the query, you can't use the Run Query (RUNQRY) command. You must use the Start Query Management Query (STRQMQRY) command as in the following example:

 STRQMQRY QMQRY(QGPL/TEST) + ALWQRYDFN(*YES) + SETVAR((COMPANY 1) + (BRANCH 1) + (ACCOUNT 12000)) 

The trick to making this work is to specify *YES for the ALWQRYDFN parameter. A value of *YES allows Query Management to run a query definition (*QRYDFN) object instead of a query management (*QMQRY) object. You can either specify values for the parameters on the STRQMQRY command or let Query Management prompt you for them.

Character fields require some additional considerations. When specifying the value to be used by a dependent character field you must enclose the value in single or triple quotes. If you let STRQMQRY prompt you for the value, you must enclose the charcter value in single quotes. If you specify the value through the SETVAR parameter of the STRQMQRY command, you must enclose the value in triple quotes.


Passing Parameters to a Query

Figure 2 Figures 2 - 3

 UNABLE TO REPRODUCE GRAPHICS 
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: