TechTip: Retrieve Query Management Query (RTVQMQRY)

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Q: I have a file on my system that I know is created by a query, but there are hundreds of queries on the system, and I'm not having any luck in finding the query that created the file. Is there a way of interrogating a query to find the culprit? The only thing I can think of is to open each query and look at the definition.

A: This might work for you. Do a Display Object Description (DSPOBJD) to an outfile to capture the names of all the queries on your system. Next, with a CL, read through the outfile and do a Retrieve Query Management Query (RTVQMQRY) on each query. This will retrieve the source of the query into the source file of your choice. Once your source file is built, you can use the scanning capabilities of PDM to scan the source members for the field names you're looking for. Unfortunately, the RTVQMQRY doesn't include what kind of output the query generated. But you can do a Display File Field Description (DSPFFD) on the file in question, get the field names, and then search the members created by the RTVQMQRY.

Figure 1 below shows how I did my DSPOBJD.

DSPOBJD OBJ (*ALLUSR/*ALL)
OBJTYPE (*QRYDFN)
OUTPUT (*OUTFILE)
OUTFILE (BRUCE/MYQUERIES)

Figure 1: Use DSPOBJD to an outfile to find all your queries

Once you have your outfile created, I suggest that you create a special source file to contain the retrieved source. I created a source file called QQRYSRC with a record length of 150 and put it into my programming "test" library.

To retrieve the source for each query, use the code in Figure 2.

          PGM                                                 
                                                                 
             DCLF       FILE(MYQUERIES)                          
                                                                 
 TOP:        RCVF                                                
                                                                 
             MONMSG     MSGID(CPF0864) EXEC(RETURN)              
             RTVQMQRY   QMQRY(&ODLBNM/&ODOBNM) +                 
                          SRCFILE(BRUCE/QQRYSRC) ALWQRYDFN(*YES) 
             GOTO       CMDLBL(TOP)                              
                                                                 
             ENDPGM                                              

Figure 2: Use this code to retrieve the source for queries on your system.

After I do the DSPOBJD and run my program, my PDM screen looks like Figure 3 when I work with the members in my QQRYSRC file.

http://www.mcpressonline.com/articles/images/2002/RTVQMQRY%20Retrieve%20Query%20Management%20QueryV600.jpg

Figure 3: Work with the members in your QQRYSRC file via PDM.

On my system, I know that I have a file that's created by a query. The name of this file is WEBQTYF1. One of the fields in my file is @ITITM#. So I'll scan all the source members for this field name and see if I can find the query.

To initiate the scan, put a '25' in the first option field, and then press F13 to repeat the option to the end of the list. Your screen should look like Figure 4.

http://www.mcpressonline.com/articles/images/2002/RTVQMQRY%20Retrieve%20Query%20Management%20QueryV601.jpg

Figure 4: Use Option #25 to scan source members in PDM


When ENTER is pressed, you'll be prompted for the search string, as shown in Figure 5:

http://www.mcpressonline.com/articles/images/2002/RTVQMQRY%20Retrieve%20Query%20Management%20QueryV602.jpg

Figure 5: Enter the search text, and set the search options.

There are a couple of parameters to watch out for. Be sure that the "Kind of match" is set to the proper case search; I always ignore case. And for our purposes here, you probably want to use option #5 (browse) instead of option #2 (edit). Using edit requires you to press F3 and then Enter to exit a source member, whereas browse requires only that you press Enter to exit a source member.

So, I've keyed in the field that I want to search for, and I've pressed Enter. When the search finds my entered text, the source member is brought up in browse mode. See Figure 6.

http://www.mcpressonline.com/articles/images/2002/RTVQMQRY%20Retrieve%20Query%20Management%20QueryV603.jpg

Figure 6: Use the PDM "Find String" option to browse or edit source members containing specific text.

In my case, I'm done searching; by comparing the fields that are selected in this query vs. the fields in my file, I can see that this is indeed the query that created my file, and using this method was a lot easier than trying to examine every query via the WRKQRY command!

Bruce Bardini is a Senior Programmer/Analyst at Bachrach Clothing, Inc., with over 15 years of experience on the AS/400. He can be reached by email at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$