The best answer is to fix the program that fails when zero records are selected. That's the actual problem.
However, you ask about how to determine if any records are available in the CL before calling the problem program. I'm not sure that there is any good way.
One possibility is to try these two commands after your OPNQRYF:
CPYFRMQRYF FROMOPNID( myqryf ) TOFILE( QTEMP/qryf ) CRTFILE(*YES) NBRRCDS(1) POSDBF OPNID( myqryf ) POSITION(*START)
The CPYFRMQRY command will try to copy one record into a file in QTEMP. It'll find a record or it won't. If it doesn't find any, there will be messages you can test to skip calling the problem program.
The POSDBF command will position the file pointer back to the *START. When you call the problem program, it should be able to read the first record along with any others that follow.
Does that make sense? You'll want to run some test CL in a small program in order to see how and when the messages will appear.
<pre>DCL VAR(&NBRCURRCD) TYPE(*DEC) LEN(10 0)
/* Build records in work file */
/* IF RECORDS EXIST */
RTVMBRD FILE(workfile) NBRCURRCD(&NBRCURRCD)
IF COND(&NBRCURRCD *GT 0) THEN(DO)
/* Process the existing records */