Passing Parm to AS400 query

Posted on 2003-12-02
Last Modified: 2007-12-19
I have a AS400 query I wanted to pass the parameters from CL program Can pass the parm to query ?
Question by:sireeshamanchala
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Accepted Solution

theo kouwenhoven earned 50 total points
ID: 9864919
Hi sireeshamanchala,

You can give some parameters to a RUNQRY, but only the one you see on the RUNQRY command, but I think you like to give selection parameters.
No, that is not possible, but you can solve that as follow.

----------- Sample CL --------------
OPNQRYF    FILE((mylib/myfile)) QRYSLT('myfield *eq' |> &MYPARM')
----------- Sample CL ------------

I'm sure there is an other way like using SQL (enentually imbedded in RPG)
but this is the easyest to manage.



LVL 14

Expert Comment

ID: 9865250
The way Murphy has given is the easiest but if it is not what you want the only other way is to use Query Management Queries.
You can write the query then split it down into extraction and prints and pass it parms
to have a look


Author Comment

ID: 9870822
Hi Murphey,
Weher do I define 'myfield'
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

LVL 16

Expert Comment

by:theo kouwenhoven
ID: 9872830
Hi sireeshamanchala,

myfield is one of the fields from the file you like to QRY
if this is an item file it can look like this:


will select all active items between parm1 and parm2.


have fun

Expert Comment

ID: 10045113
1. Create a file that will "hold" your parameters values
2. Create the query reading the parameter file and selecting from the "real" data files.
3. You can aso prompt the user to fill in the parameter file before running the query.

Good Luck
LVL 27

Expert Comment

ID: 10819513
Ummm... you can pass parms into queries -- either Query/400 *QRYDFNs or Query Manager *QMQRYs -- by properly defining the queries in the beginning and then running them correctly. Overall, QM queries are superior and also easier to pass parms into.

To pass parms into a *QRYDFN, create what's called a "dependent query". Use any dummy name when prompted for the dependent file for the dependent column value since you won't actually use an additional file anyway. To run, use the STRQMQRY command specifying ALWQRYDFN(*YES) and supplying the *QRYDFN name for the QMQRY() parm. Whatever you typed for the dependent column name will be prompted back to you for a value. You can instead supply this via the SETVAR() parm to avoid prompting, thereby "passing in a parm to Query/400".

To pass parms into QM queries, use standard substitution variables in the QM query SQL statement. The substitution variable names will be prompted for just as above when you run the QM query with STRQMQRY. Again, SETVAR() can be used to avoid prompting.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question