"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi
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
use
GO CMDQM
to have a look

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.

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.