The RTVQMQYRY command provides another useful method for retrieving query definitions. The resulting source member contains the names of the files used in the format: library/filename. These could readily be parsed out with a simple RPG program (scan for the forward slash). To process multiple queries use a dedicated source file, and precede the RPG with a CL program that does an OVRDBF MBR(*ALL).
PGM DCLF FILE(QADSPOBJ) /* Obtain a list of queries in mylib */ DSPOBJD OBJ(mylib/*ALL) OBJTYPE(*QRYDFN) OUTPUT(*OUTFILE) OUTFILE(QTEMP/myfile) OVRDBF FILE(QADSPOBJ) TOFILE(QTEMP/myfile) /* Process the list */ LOOP: RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EXIT)) /* Retrieve the query definition to a source member in qtxtsrc in mylib */ RTVQMQRY QMQRY(&ODLBNM/&ODOBNM) SRCFILE(myib/QTXTSRC) SRCMBR(*QMQRY)ALWQRYDFN(*YES) GOTO LOOP: EXIT: ENDPGM
This was first published in May 2001