After writing the post about Retrieving the print file name from a Query it struck me that I could use the same methodology to answer a question I have been asked on several occasions: Which Querys are using a particular file?
I cannot answer which Querys are using a file. I can list all the files that Querys are defined to use.
What are the steps I need to perform to get that information:
- Make a list of all the Querys in a particular library
- Print their definitions using PRINT_QUERY_DEFINITION
- Extract the file names from the spool file, and write them to an output file
I am going to show you how I manually executed the above steps. And then I will show a program I created to do the same thing.
First, I need to make a list of all the Querys in a library, MYLIB. I will use the OBJECT_STATISTICS SQL Table function.
01 SELECT OBJLIB,OBJNAME
02 FROM TABLE(QSYS2.OBJECT_STATISTICS('MYLIB','*QRYDFN','*ALL'))
|
Line 1: I only want the Query library and name in my results.



