|
Print Query Definitions from a Batch Job
Hey, Ted:
I can print the definition of a Query/400 query by
running the Work with Queries (WRKQRY) command and choosing
option 6. Is there a way I can print a query definition
from a CL program? I would like to write a program that
will find all the queries in a library and print their
definitions.
-- Curtis
There is no direct equivalent to the Print definition
function of WRKQRY, but you can get close. The Run Query
(RUNQRY) command has a PRTDFN parameter that will cause
Query to print the report definition. If you don't want the
output of the Query, but only want the definition, you can
send the output to a temporary file in QTEMP. You can keep
the size of this temporary file small (and presumably make
the job run slightly faster) by specifying that you want
summary output rather than detail output. The following
command prints the definition of a query called
CUSTLIST00:
RUNQRY QRY(CUSTLIST00) +
OUTTYPE(*OUTFILE) +
OUTFORM(*SUMMARY) +
PRTDFN(*YES) +
OUTFILE(QTEMP/Q0001)
To find the queries in a library, use the Display Object
Description (DSPOBJD) command to search for objects of type
*QRYDFN:
DSPOBJD OBJ(THOLTS/*ALL) +
OBJTYPE(*QRYDFN) +
OUTPUT(*OUTFILE) +
OUTFILE(QTEMP/QUERYLIST)
Here's a short program that puts the preceding examples
to work. I call it QRYLIST. I hope it helps:
/* QRYLIST -- Print definitions of queries in */
/* a library. */
PGM PARM(&LIB)
DCLF QADSPOBJ
DCL &LIB *CHAR 10
DCL &FILENBR *DEC 9
DCL &FILENAME *CHAR 10 +
VALUE(Q)
MONMSG MSGID(CPF0000) EXEC(GOTO ERROR)
DSPOBJD OBJ(&LIB/*ALL) OBJTYPE(*QRYDFN) +
OUTPUT(*OUTFILE) +
OUTFILE(QTEMP/QUERYLIST)
OVRDBF FILE(QADSPOBJ) TOFILE(QTEMP/QUERYLIST)
READ:
RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOJ))
CHGVAR VAR(&FILENBR) VALUE(&FILENBR + 1)
CHGVAR VAR(%SST(&FILENAME 2 9)) VALUE(&FILENBR)
RUNQRY QRY(&ODLBNM/&ODOBNM) OUTTYPE(*OUTFILE) +
OUTFORM(*SUMMARY) PRTDFN(*YES) +
OUTFILE(QTEMP/&FILENAME)
GOTO READ
ERROR:
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Error in QRYLIST -- see job log') +
MSGTYPE(*ESCAPE)
MONMSG CPF0000
EOJ:
DLTOVR FILE(QADSPOBJ)
ENDPGM
-- Ted
|