Options

division by zero. 0/0 problem

mark_christsmark_christs Member Posts: 156
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

Comments

  • Options
    andreofandreof Member Posts: 133
    Substitute this :

    "Remaining Quantity" := "Expected Quantity" - "Act. Consumption (Qty)" / "Qty. per Unit of Measure";

    whith this:

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


    OR just populate "Qty. per Unit of Measure" field


    Hope this helps

    Regards
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • Options
    mark_christsmark_christs Member Posts: 156
    Dear Friend,
    Tks for youranswer but I will write the overall codings firsts:
    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");
    
    
    


    So, I am afraid if the substitute will influence another, nevertheles I will try then.


    Rgds,
  • Options
    BalelloBalello Member Posts: 61
    I think the question must be "why "Qty. per Unit of Measure" is equal to "0"?".
    I didn't check, so please forgive me if I'm wrong, but I think it's better if you look if your Unit of Measure conversions for that Item, WorkCenter etc. are all right.
    I don't envy anybody who caught up his aim. I travel gladly.
  • Options
    DenSterDenSter Member Posts: 8,304
    The code should catch the divide by zero, so that is a candidate for a bug report to Microsoft (if it's part of the standard objects as well). I do agree that your problem should go away as soon as you fix the quantity per unit, which should always have a value.
  • Options
    David_CoxDavid_Cox Member Posts: 509
    I think if you look system wide the "Qty. per Unit of Measure" has an Init value of 1.

    So check 2 things firstly is the field properties for this table set to 1, second how was the table filled.

    If it is set to 1, then how were these values input, the only way it could be Zero, is if the value set to zero either created in code or dataported in without an validate or table.INIT on the record.
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    DenSterDenSter Member Posts: 8,304
  • Options
    David_CoxDavid_Cox Member Posts: 509
    I had a look at table 5407 the Init value is undefined, and the field is uneditable, this field is filled when other fields are validated, so you need to look at the Item on the line and view Item Units of Measure, against the Unit of Meassure code on the line, but the code which fills this value should always return a value, so has anything been changed on your system.

    See this Code from #5407

    Item No. - OnValidate()
    ~
    Item.TESTFIELD("Base Unit of Measure");
    VALIDATE("Unit of Measure Code",Item."Base Unit of Measure");
    ~

    This calls
    Unit of Measure Code - OnValidate()
    ~
    "Qty. per Unit of Measure" := UOMMgt.GetQtyPerUnitOfMeasure(Item,"Unit of Measure Code");
    "Quantity (Base)" := CalcBaseQty(Quantity);
    ~

    So it looks like the line was filled without validating the Item No., or you have bad data in the "Item unit of Measure" Table #5404, which will not allow a zero Quantity Per., this field has init = 1 and not blank = yes, but that only works if data is entered by hand, you can dataport rubbish into tables, so always validate the fields, the same sequence as manual input, that will trap errors! :D

    End of Investigation ! :roll: "I must get out more!" :?
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • Options
    PellePelle Member Posts: 18
    David Cox wrote:
    "I must get out more!" :?

    Why do you have to get out more?

    //Range Check Error
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Pelle wrote:
    Why do you have to get out more?

    It's 10:30 pm in the UK, and I am looking at Navision, in the evening after looking at it all day! ](*,)
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    mark_christsmark_christs Member Posts: 156
    Dear All,
    Tks for your replies/answers. :)
    I actually suing this coding from Andreof:
    IF "Qty. per Unit of Measure" <> 0 THEN...

    It works but another database can work without the new coding that supposed by Andreof.
    The things that I don't understand that I have another database, but it can works good, there is no. problem, regarding your replies, I will check item's unit of measure, item no., and work center / machine center.


    Rgds,
    Mark
  • Options
    BalelloBalello Member Posts: 61
    I think that "Qty. per Unit of Measure" must always have a value. So I don't think the andreof solution will work in this environment (even if it's the right solution sometimes). This could create problems. I agree with DenSter that there should be an error "catch" in the sense that there should be an explaining error message, but this field value is to much important to permit the code to avoid error messages.
    Moreover the code:
    IF "Qty. per Unit of Measure" <> 0 THEN
    "Remaining Quantity" := "Expected Quantity" - "Act. Consumption (Qty)" / "Qty. per Unit of Measure"
    ELSE
    "Remaining Quantity" := "Expected Quantity";

    insert an error (it doesn't consider the consumption if you don't set "Qty. per Unit of Measure").
    You must "solve" and not "workaround" the problem, this time. :(

    And my candidate... obviously Dataport :wink:
    I don't envy anybody who caught up his aim. I travel gladly.
Sign In or Register to comment.