Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
When I display a list of queries created by the wrkqry command, one of the command options is '6', to print the query definition.
Is there a command that I could use in a CL program - or at the command line - that I could use with a driver file to print the query definitions for all of the queries that are named in the driver file?
Or am I stuck using '6' for every query in the library, to print the definitions?
See "Query for i5/OS", V6R1, SC41-5210-05, Ch. 16. Basically, you can WRKQRY opt 6, you can print it as you exit when creating or changing, or on RUNQRY use PRTDFN(*YES). The problem with RUNQRY PRTDFN() is you are actually running the query, too, so not real useful.
But what are you trying to accomplish?
Do you have SQL installed, which also includes Query Manager? You could RTVQMQRY with ALWQRYDFN(*YES or *ONLY), which retrieves the *QRYDFN into a source member. QM format has some cryptic codes, but there's a plainly visible SELECT statement, which gives you tables, columns, and selection criteria. It won't give you report layout.
If all you need to know is what files are referenced, that's available from *QRYDFN objects as of V6R1. Just DSPPGMREF mylib/myqry OBJTYPE(*ALL or *QRYDFN). Also see PTF SI34166; it provides a program that adds the file usage info to queries create prior to V6R1.
0001.00 PGM PARM(&LIB) 0002.00 DCL VAR(&LIB) TYPE(*CHAR) LEN(10) 0003.00 DCLF FILE(MyLib/Outfile) RCDFMT(QLIDOBJD) 0004.00 CLRPFM FILE(MyLib/Outfile) 0005.00 CLRPFM FILE(MyLib/YourSRCPF) MBR(QRYLIST) 0006.00 DSPOBJD OBJ(&LIB/*ALL) OBJTYPE(*QRYDFN) + 0007.00 OUTPUT(*OUTFILE) OUTFILE(MyLib/QRYLIST1) 0008.00 NEXT: RCVF RCDFMT(QLIDOBJD) 0009.00 MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)) 0010.00 RTVQMQRY QMQRY(&ODLBNM/&ODOBNM) + 0011.00 SRCFILE(MyLib/QQRYSRC) ALWQRYDFN(*ONLY) 0012.00 CPYF FROMFILE(MyLib/QQRYSRC) + 0013.00 TOFILE(MyLib/QQRYSRC) FROMMBR(&ODOBNM) + 0014.00 TOMBR(QRYLIST) MBROPT(*ADD) 0015.00 GOTO CMDLBL(NEXT) 0016.00 END: ENDPGM
I use above program to get a list/definition of all queries in a single SRC file (QQRYSRC) as well as the definition of all queries into a single source [MyLib/QRYLIST(QRYLIST)]
HTH
Deepak