RNQ0102: Divide by zero
RNQ0102 means an ILE RPG program tried to divide a number by zero. It matches RPG program status code 00102, and the program has stopped to wait for a reply because nothing in it handled the error.
Other names for this code
Also written as RNX0102, status 00102, RPG status 102, %STATUS 102, RPG divide by zero, RNQ0102 divide by zero.
What it means
RNQ0102 is an ILE RPG runtime message. Its number is the RPG program status code, so it reports status 00102, which IBM's ILE RPG Reference lists as divide by zero. Any division can raise it. That includes the / operator in an expression, the DIV operation code in fixed-form code, and the %DIV and %REM built-ins.
Underneath, the machine raises its own divide-by-zero exception, and the job log usually shows MCH1211 just before the RPG message. The RPG runtime turns that into status 00102 and gives the program a chance to handle it. When the program has no handler, the RPG default handler sends RNQ0102 and the job waits.
RNQ and RNX messages with the same number mean the same thing. RNQ0102 is the inquiry form. Somebody has to reply, either at the user's screen or, for a batch job, usually in QSYSOPR. RNX0102 is the escape form. It doesn't wait for a reply, and it is what a MONITOR group or a calling program sees.
Common causes
- An average or ratio where the count is zero, for example total sales divided by number of orders on a day with no orders.
- A percentage of a base value that is zero for a new customer, item or period.
- A divisor read from a file or a table that was never filled in, so it is still zero.
- A parameter that the caller didn't pass or passed as zero.
- A rate or factor that a user typed as 0 on a screen that doesn't validate it.
How to find the problem
- Press F1 on the message to see the help text. It names the procedure, the program and the statement number. In a batch job, DSPMSG QSYSOPR or DSPJOBLOG shows the same message.
- Look for MCH1211 just above it in the job log. It confirms that the problem is a zero divisor and not a different arithmetic error.
- Find the statement in the compile listing and note which field is the divisor. Then check where that field gets its value.
- Reply D if you want a formatted dump. It shows the value of every field in the program when it failed.
How to fix it
- Test the divisor before dividing, for example with
IF count <> 0. When it is zero, set the result to zero or skip the record. - Catch it where the program can recover. A MONITOR group with
ON-ERROR 00102lets the program set a default and carry on. - Add a *PSSR subroutine as a last line of defence, so unexpected errors are logged and the program ends in a controlled way.
- Validate screen input so a user can't enter zero in a field that is later used as a divisor.
- For the job that is waiting now, reply C to cancel it. Fix the data or code, then rerun.
IBM documentation
IBM Display Message Descriptions (DSPMSGD). Use the documentation for your installed release.
This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.
Related codes
Questions
Why do I see MCH1211 and RNQ0102 together?
MCH1211 is the machine's divide-by-zero exception. The RPG runtime maps it to status 00102 and, when the program doesn't handle it, sends RNQ0102 to ask for a reply.
Can I catch divide by zero in RPG?
Yes. Put the division in a MONITOR group with ON-ERROR 00102, or let a *PSSR subroutine handle it. Testing the divisor first is simpler and clearer.
Which reply should I give to an RNQ message?
C (cancel) is the safe answer when you don't know the program. D and F also cancel, but first write a dump the developers can use. G skips the rest of the current RPG cycle and resumes at its input step (*GETIN). That is a call for the program's owner to make.