More on retrieving query source

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

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.