Did OPNQRYF Retrieve Records?
July 24, 2002 Timothy Prickett Morgan
Here is a tip you may want to print. Sometimes I need to find out if an Open Query File (OPNQRYF) selection contains any records. For instance, I may want certain programs to run only if OPNQRYF did not select any records. I run the following commands after OPNQRYF runs:
/* Copy 1 record for testing purposes */ CPYFRMQRYF FROMOPNID( IVRPTHDQ ) + TOFILE( QTEMP/@DUMMY ) MBROPT( *REPLACE ) + CRTFILE( *YES ) + NBRRCDS( 1 ) RTVMBRD FILE( QTEMP/@DUMMY ) + NBRCURRCD( &RCNT ) IF ( &RCNT *GT 0 ) THEN( DO ) POSDBF IVRPTHDQ *Start CALL Program ENDDO
Of course, this code won’t tell you how many records were retrieved, but knowing that at least one record was retrieved or that none were retrieved is sufficient for the vast majority of the cases.
Thanks for the tip, Mark. This is the best solution I’ve ever found, and it’s the one I’ve used through the years.
The Training and Mentoring Company (Tramenco) is dedicated to just one thing: Advancing your career by giving you the skills you need to solve real-world business problems.
Choose from a menu of training options to fit your needs: onsite seminars, public seminars, mentoring, consulting, books, CBTs, and Web-based training.
For more information about Tramenco’s career enhancing opportunities, call (800)421-8031 or go to www.tramenco.com.