Guild Companies, Inc.  
ASC
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 39 - May 22, 2002

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

ASC

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

Sponsored By
ADVANCED SYSTEMS CONCEPTS

SEQUEL meets all your iSeries and AS/400 data access needs in a single, integrated solution:

  • Windows, Web or host user interfaces
  • Convert AS/400 data into PC file formats
  • E-mail or FTP query results, reports and spool files
  • Run-time prompted queries and reports for end users
  • IF-THEN-ELSE logic in queries and reports
  • Report, form and label formatting second to none
  • Easily convert date fields, character-to-numeric, numeric-to-character and other data manipulation
  • SORT or JOIN using a calculated field
  • Quick summarization of data with Tabling function
  • Run multiple SEQUEL requests as one with the SEQUEL Scripting function
  • OLAP Business Intelligence at a fraction of the cost of comparable solutions

Take 6 minutes to view a SEQUEL ViewPoint ScreenCam movie to see how simple Windows-based AS/400 and iSeries data access can be! In just a few short minutes, you can find out ways to make your job easier and improve data access throughout your organization. Download the ViewPoint movie here .

For more information or a FREE trial of SEQUEL, call 847/605-1311 or visit Advanced Systems Concepts .

THIS ISSUE
SPONSORED BY:
Advanced Systems Concepts
ASNA
BACK ISSUES
TABLE OF CONTENTS
Print Query Definitions from a Batch Job
You Can Re-IPL an AS/400 into Restricted State
Reader Feedback and Insights: I Didn't Know You Could Do That
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 5/21/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.