division by zero. 0/0

Dear All experts,
There is always a pop message windows said: “division by zero. 0/0” if I try to change unit cost per field in the production order routing line. If I used debugger it shows (in the red arrow) these coding (table # 5407) of expected quantity (on validate) field:

IF (Status IN [Status::Released,Status::Finished]) AND
(xRec.“Item No.” <> ‘’) AND
(“Line No.” <> 0)
THEN
CALCFIELDS(“Act. Consumption (Qty)”);
“Remaining Quantity” := “Expected Quantity” - “Act. Consumption (Qty)” / “Qty. per Unit of Measure”;

If I delete the codings, what I want to do is work good. Also if I don’t delete them but delete this coding in the table # 5409 of field unit cost per:

CalcStartingEndingDates(Direction::Forward);

I have been trying to solve it but not succeed good. Could you give me some solutions for the problems ??
I set the items and all relevant fields manually and standard costing, no inventory exists. Thanks in advance for your answers. I expect them a lot.

Rgds,

Mark

Probably the “Qty. per Unit of Measure” is Zero. to avoid the “division by zero” error try:

IF (Status IN [Status::Released,Status::Finished]) AND
(xRec.“Item No.” <> ‘’) AND
(“Line No.” <> 0)
THEN
CALCFIELDS(“Act. Consumption (Qty)”);

// Avoid “Division by Zero”

IF “Qty. per Unit of Measure” <> 0 THEN
“Remaining Quantity” := “Expected Quantity” - “Act. Consumption (Qty)” / “Qty. per Unit of Measure”;

Sorry, but looking at my first post, it’s incomplet, because the change in the Code will only avoid the error message. The root cause seems to be, that the “Qty. per Unit of Measure” = 0 where it should not be. So maybe all you have to do is have a look at that “Item Unit of Measure” and change the “Qty. per Unit of Measure” field to the correct value (it probably is 0 at the moment), and then try again.

Hi Daniel, although your solution is technically correct. I really think that in this case the isse needs to be resolved at the source. i.e. why is the “Qty. per Unit of Measure” zero. The source of this error needs to be found and corrected, and then a routine run to correct the errors int he data. Other wise this error will cause problems in many other areas, such as reports, inventory revaluations etc.

By the way, this isse was ver common in upgrading form the versions prior to base unit of measure existing (2.00 I think to 2.60), and I have seen addons written for 200 ported badly to 2.60 and then as far up as the latest versions without being fixed.

Tks for your answers, but I wonder why I must write :

IF “Qty. per Unit of Measure” <> 0 then …, meanwhile the other codings like belows:

IF Item.GET(“Item No.”) THEN
IF Item.“Rounding Precision” > 0 THEN
“Expected Quantity” := ROUND(“Expected Quantity”,Item.“Rounding Precision”,’>’);
“Expected Qty. (Base)” := “Expected Quantity” * “Qty. per Unit of Measure”;
IF (Status IN [Status::Released,Status::Finished]) AND
(xRec.“Item No.” <> ‘’) AND
(“Line No.” <> 0)
THEN
CALCFIELDS(“Act. Consumption (Qty)”);
“Remaining Quantity” := “Expected Quantity” - “Act. Consumption (Qty)” / “Qty. per Unit of Measure”;
IF (“Remaining Quantity” * “Expected Quantity”) < 0 THEN
“Remaining Quantity” := 0;
“Remaining Qty. (Base)” := ROUND(“Remaining Quantity” * “Qty. per Unit of Measure”,0.00001);
“Completely Picked” := “Qty. Picked” >= “Expected Quantity”;

ReserveProdOrderComp.VerifyQuantity(Rec,xRec);

“Cost Amount” := ROUND(“Expected Quantity” * “Unit Cost”);
“Overhead Amount” :=
ROUND(
“Expected Quantity” *
((“Direct Unit Cost” * “Indirect Cost %” / 100) + “Overhead Rate”));
“Direct Cost Amount” := ROUND(“Expected Quantity” * “Direct Unit Cost”);

don’t have the new code mentioned firsts above. It can be concluded sometimes Navision can’t calculate without the additional codings and sometimes it can. The IF condition is a requirement to make the formula work, isn’t it ? but the codings I copy from other database and paste here is work good. It must be prohibited…

Rgds,

Mark

Mark please read the response that you replied to. [;)]

Navision, as any other arithmetic tool (fingers included) can’t perform a division by zero. The reason because you find unprotected code which works neatly is that “Qty. per Unit of Measure” is not supposed to ever be 0. Nevertheless, sometimes users are so smart to succeed in making that happen.
Usually it happens when an Item card is copied from an other one using a select/copy/paste sequence. The “Basic Unit of Measure” is copied from the old card to the new one, but the underlying “Item Unit of Measure” table is obviously not and if the user forgets (as it is likely) to fill it manually, it will remain unfilled and… BOOOOMMM!!!
Look for item nos. existing in table 27, but non-existing in table 5404 and you will discover the cause of your troubles.
About how to solve it… to next lesson! [;)]

Hi Anne,

Im not 100% sure, but fairly certain that there really is no way you could create a Production Order Component in Navision unless you have a Base Unit of measure. Even if you copy the Item card, you then would not be able to use that item card.

I really think (as in my first post), that fundamentally there is a bug that they have written somewhere that is causing this. I just can’t see a scenario that would create a Prodcution Order Component with “Qty. per Unit of Measure” = 0.

I think the first issue is to find the code causing the bug and fix that.

I can’t say by sure about Production Order Component, but I’m quite sure I’ve seen items with ledger entries and no entries in table 5404, which is where “Qty. per Unit of Measure” is stored. On the Item card the “Basic Unit of Measure” is filled, so everything works until a division is attempted.
The interesting thing is that, if you try to insert an Item Unit of Measure and fill the “quantity per” an error occurs saying you can’t modify the “Qty. per Unit of Measure” because the item has ledger entries. [:P]

Of course the copy thing is just my best guess.

Hi Anne,

can you duplicate this? If you can then I would say that this is a Navision bug, and needs to be reported. I have tired a few things, but can not duplicate it.

If this is a new bug in 4.00, then I would like to find out.

Hi David,

Tks for your comments. I will check

Rgds,

Dear David,

You are 100% correct, I am currently using the table again and there is no coding I added, except I rewrite work center, check purchase unit of measure (conversion unit of measure from base unit of measure to purchase unit of measure: CM and Yard), I import the table from original database to the problem database, so I replace the database that give me problems, and it works good. there is no division by zero. 0/0 problem any more. but yesterday it comes. because I can’t understand a lot the thorough codings, I am agree with your statement:

David’s Quote:

I really think (as in my first post), that fundamentally there is a bug that they have written somewhere that is causing this. I just can’t see a scenario that would create a Prodcution Order Component with “Qty. per Unit of Measure” = 0.

I think the first issue is to find the code causing the bug and fix that.

Rgds,

Mark

No, in version 4 I can’t duplicate it, neither in 3.70. [:$]

The database where I found that situation started in 2.50, then was migrated to 3.60, then to 3.70a. The item ledger entries without Qty per Unit of Measure were old enough to have been created in 2.50 and the involved items were just one or two - too few to think of a massive bug, like a posting routine using the UM factor to calculate the Quantity in Basic Unit of Measure and then missing to copy it into the Ledger Entry record. That made me think of a possible human mistake. After managing to correct the situation (not without struggle!) it didn’t show up anymore. [8-)]