Troubleshooting
Problem
This document explains how to pass parameters to a Query/400 query.
Resolving The Problem
Parameters can be passed to a Query/400 query (object type *QRYDFN). 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.)
Figure 2: The Select Records Panel
After setting up the parameters, press the Enter key to obtain a screen similar to Figure 3. Simply enter the qualifier type as 1 and any name for the query name. In our example, we chose DUMMY. The name supplied is irrelevant, as it is not used in the execution of the query.
Figure 3: Specifying a Dummy Dependent Value Qualifier
Note: The host variable name(s) are case sensitive. The host variable defined in the query selection must match the host variable defined in the STRQMQRY command.
Host variables should be defined before any other record selection criteria in your query. For example, if you are performing tests of GLCOMP equal to 100 and GLBRAN equal to a host variable, the record selection test should be defined as:
To run the query, you cannot use the Run Query (RUNQRY) command. You must use the Start Query Management Query
(STRQMQRY) command, as in the following example:
STRQMQRY QMQRY(library/qry-name) ALWQRYDFN(*YES) +
QMFORM(*QMQRY) SETVAR((COMPANY 1) (BRANCH 1) (ACCOUNT 12000))
The parameter that makes this work is the value of *YES for the ALWQRYDFN parameter. A value of *YES allows Query Management to run a query definition (*QRYDFN) object rather than a query management (*QMQRY) object type. You can 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 character 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.
Notes:
Figure 2: The Select Records Panel
Select Records Type comparisons, press Enter. Specify OR to start each new group. Tests: EQ, NE, LE, GE, LT, GT, RANGE, LIST, LIKE, IS, ISNOT... AND/OR Field Test Value (Field, Number, 'Characters', or ...) GLCOMP EQ :COMPANY AND GLBRAN EQ :BRANCH AND GLACC EQ :ACCOUNT -----------------------------------------------------------------------
After setting up the parameters, press the Enter key to obtain a screen similar to Figure 3. Simply enter the qualifier type as 1 and any name for the query name. In our example, we chose DUMMY. The name supplied is irrelevant, as it is not used in the execution of the query.
Figure 3: Specifying a Dummy Dependent Value Qualifier
----------------------------------------------------------------------- Specify Dependent Value Qualifiers Type choices, press Enter. Qualifier type ....... 1 1=Query 2=File Query or File ....... DUMMY Name, F4 for list of files Library .......... *libl Name, #LIBL, F4 for list For choice 2=File: file member ........ Name, *First, F4 for list -----------------------------------------------------------------------
Note: The host variable name(s) are case sensitive. The host variable defined in the query selection must match the host variable defined in the STRQMQRY command.
Host variables should be defined before any other record selection criteria in your query. For example, if you are performing tests of GLCOMP equal to 100 and GLBRAN equal to a host variable, the record selection test should be defined as:
GLBRAN EQ :BRANCH AND GLCOMP EQ 100 -----------------------------------------------------------------------
To run the query, you cannot use the Run Query (RUNQRY) command. You must use the Start Query Management Query
(STRQMQRY) command, as in the following example:
STRQMQRY QMQRY(library/qry-name) ALWQRYDFN(*YES) +
QMFORM(*QMQRY) SETVAR((COMPANY 1) (BRANCH 1) (ACCOUNT 12000))
The parameter that makes this work is the value of *YES for the ALWQRYDFN parameter. A value of *YES allows Query Management to run a query definition (*QRYDFN) object rather than a query management (*QMQRY) object type. You can 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 character 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.
Notes:
1 | Output goes to display unless specified within the STRQMQRY command. In a batch environment, the default will be to the printer. The spooled file that would be created is called QPQXPRTF. |
2 | This is an unsupported example of passing parameters to a Query/400 query. Therefore, a detailed explanation of this document must be handled under a consulting agreement. |
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CQbAAM","label":"IBM i Db2-\u003EQuery\/400"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
6515952
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
IBM i Db2->Query/400
Software version:
All Versions
Operating system(s):
IBM i
Document number:
706471
Modified date:
04 December 2024
UID
nas8N1010660
Manage My Notification Subscriptions