MCH1211: Attempt made to divide by zero
MCH1211 means a program on IBM i tried to divide a number by zero. The machine stops the division and sends MCH1211 to the program, which ends unless it handles the error.
Other names for this code
Also written as MCH1211 error, MCH1211 divide by zero, attempt made to divide by zero, MCH1211 RPG, divide by zero AS400, MSGID MCH1211.
What it means
Division by zero has no answer, so the machine refuses to do it. When a fixed-point divide instruction gets a divisor of zero, the machine sends MCH1211 as an escape message to the program that ran it. The message text says an attempt was made to divide by zero for a fixed-point operation.
Any division can cause it. That includes the / operator in an RPG expression, the DIV operation code, the %DIV and %REM built-ins, a COBOL DIVIDE or COMPUTE, and arithmetic in CL. An ILE RPG program reports it as status 00102 and, with no handler, shows inquiry RNQ0102. Other programs end in their own inquiry or in function check CPF9999.
The divisor is almost always a field that is zero because of the data, not a literal zero in the code. A percentage, an average or a unit price works until the day a record arrives with zero in the field below the line.
Common causes
- A record has zero in a field used as a divisor, such as a quantity, a count or a total, for example an order line with no quantity or a month with no sales.
- A field used as a divisor was never set, so it still holds zero.
- An average was calculated over an empty group, such as total divided by count when no records matched.
- A user keyed zero, or left a numeric field blank, on a screen that feeds a calculation.
- Less often, an IBM program or API is the one named. That can happen when it was passed a length or count of zero. Check the parameters first, then the PTF level.
How to find the problem
- Run
DSPJOBLOG, put the cursor on MCH1211 and press F1, then F9. The message details name the program, module, procedure and statement that did the division. - Look at the divisor in that statement and work back to where it gets its value.
- Find the record or screen input being processed when the job failed. In debug (
STRDBG), stop on the statement and display the divisor to confirm it is zero. - If the program named is an IBM program, look at the program just above it in the call stack, since that is usually the caller that passed the bad value.
How to fix it
- Test the divisor before every division whose divisor comes from data, and decide what the result should be when it is zero. Often that is zero, or a message.
- In RPG, wrap the calculation in
MONITORandON-ERROR 00102, or check%STATUSin a*PSSRroutine, so one bad record doesn't stop a batch run. - In COBOL, use
ON SIZE ERRORon theDIVIDEorCOMPUTEstatement. - In CL, check the variable before
CHGVARdoes the division, or monitor for MCH1211. - Fix the data or the screen validation that let a zero through where the business needs a value.
What it looks like
Attempt made to divide by zero for fixed point operation.
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.
Read the installed message description:
DSPMSGD MSGID(MCH1211) MSGF(QSYS/QCPFMSG)
Also inspect the full job log and second-level message text, including substitution values.
Related codes
Questions
What RPG status code does MCH1211 map to?
Status 00102, divide by zero. If nothing handles it, the RPG runtime shows inquiry RNQ0102, and RNX0102 is the escape form a MONITOR group can catch.
Can I just reply to the inquiry and let the program carry on?
Only if you know what the program does next. An RPG program asks with RNQ0102 and a CL program with CPA0701. Replying G to RNQ0102 or I to CPA0701 lets the program go on without the division, so a result field may keep an old value. Reply C and fix the data or the code when in doubt.
Why does the job log say MCH1211 was unmonitored by an IBM program such as an API?
The division happened inside that program, but the bad value usually came from its caller. Check the lengths and counts your program passed, and if they look right, check the PTF level.