One of the problems with running a query from within a CL program is that, by default, queries don't use the library list to find the file they were designed to access. When the query is defined, the name of the library for the file is essentially hard coded into the query. One way to get around this problem is to use the QRYFILE parameter of the RUNQRY command. Here, you can specify the name of the original file and *LIBL for the library name.
For example, suppose you have a query called HISTQRY that was designed to read file ITEMHIST in library PRODLIB. You can force the query to read the first occurrence of the ITEMHIST file in your library list by placing the following command into your CL program:
RUNQRY QRY(HISTQRY) + QRYFILE((*LIBL/ITEMHIST))
In this example, if another copy of the ITEMHIST file was in a library called TESTLIB that was higher in the library list than PRODLIB, then the query would read the file from TESTLIB. If you then removed TESTLIB from your library list, the query would read the file in PRODLIB. This technique gives your queries more flexibility by forcing them to use the library list to locate the files they were designed to read.
- Blair Hamren
LATEST COMMENTS
MC Press Online