CALCIFIED does not working!!

I have two record variable of ITEM table and another one is Transferline table(Created by me).
ItemRec.SETFILTER(ItemRec."Location Filter",TransferLine."Warehouse Location");
ItemRec.GET(TransferLine."Item No");
MESSAGE('At %1 Location for Item %2',ItemRec."Location Filter",ItemRec."No.");
END;
ItemRec.CALCFIELDS("Qty. on Purch. Order");
CalcifieldVar := ItemRec."Qty. on Purch. Order";
IF CalcifieldVar >= PurchaseQuantityRequired THEN BEGIN
MESSAGE('For this Item %1 Quantity on purchase order is %2',TransferLine."Item No",ItemRec."Qty. on Purch. Order");

Best Answers

Answers

  • frischfrisch Member Posts: 20
    So what's not working then? I think it would be good to explain what you're expecting (and why, as in: what's your business requirement?), what you're getting, and maybe what you tried to get it work.

    Concerning your code: I didn't look through the whole thing, but the first are a bit weird to me.

    You call an ItemRec.SETFILTER (personal preference: I'd use a SETRANGE).
    Then you call ItemRec.GET, which will ignore (but not remove) all filters set.

    Are you trying to calculate the qty. on purchase order for a certain location? If so -> The flowField in ItemRec will also ignore your filter.
  • kylehardinkylehardin Member Posts: 257
    What is the output of the second MESSAGE statement?

    Concur with frish - GET ignores any filters, so the SETFILTER is a wasted statement.
    Kyle Hardin - ArcherPoint
  • RockWithNAVRockWithNAV Member Posts: 1,139

    ItemRec.SETFILTER(ItemRec."Location Filter",TransferLine."Warehouse Location");

    Remove the above line. Why using setfilter if using GET???

    ItemRec.GET(TransferLine."Item No"); This is enough

  • vaprogvaprog Member Posts: 1,140
    edited 2016-10-05
    Hei Experts,

    Don't confuse SuD any more. "Location Filter" is a FlowFilter field used in calculating the "Qty. on Purch. Order" FlowField, so that code is sensible.

    The order of the statements is unusual, but not wrong. I assume, code not relevant to the question has been purged.

    At the first MESSAGE, I'd expect the location shown to be empty (The value is in the filter, not the field). Although, I am not entirely sure how the FlowFilter field behaves in this regard.

    I assume, the END; -line is there for a good reason, and the code before it is executed, as the code excerpt suggests.

    The rest of the code looks to be ok.

    What is the result you get, what do you expect to get, and why.
  • SuDSuD Member Posts: 102
    Thank you for your suggestions guyzz..But it was a problem of Infinite loop that first time i faced....:(
  • SuDSuD Member Posts: 102
    ItemRec.SETFILTER(ItemRec."Location Filter",TransferLine."Warehouse Location");

    Remove the above line. Why using setfilter if using GET???

    ItemRec.GET(TransferLine."Item No"); This is enough

    I want to filter items by location wise ,when i select a item from lookup table in my Transfer Line..Thats why i using setfilter after GET!!!
  • KishormKishorm Member Posts: 921
    There are no loops in the code you have posted so if the problem is an infinite loop then you need to post more code - i.e. all the code in the loop
  • SuDSuD Member Posts: 102
    ItemRec.SETFILTER(ItemRec."Location Filter",TransferLine."Warehouse Location");

    Remove the above line. Why using setfilter if using GET???

    ItemRec.GET(TransferLine."Item No"); This is enough

  • SuDSuD Member Posts: 102
    Kishorm wrote: »
    There are no loops in the code you have posted so if the problem is an infinite loop then you need to post more code - i.e. all the code in the loop

    :s TransferLine.SETRANGE(TransferLine."Document No.",Rec."Document No.");
    IF TransferLine.FINDSET THEN REPEAT
    TransferLine.CALCFIELDS(TransferLine."Quantity in Hand at WL");
    PurchaseQuantityRequired := TransferLine."Quantity Required" - TransferLine."Quantity in Hand at WL";
    MESSAGE('Quantity Required Final%1',PurchaseQuantityRequired);
    IF TransferLine."Quantity Required" > TransferLine."Quantity in Hand at WL" THEN BEGIN
    ItemRec.SETRANGE(ItemRec."No.",TransferLine."Item No");
    ItemRec.SETFILTER(ItemRec."Location Filter",TransferLine."Warehouse Location");
    IF ItemRec.FINDFIRST THEN
    MESSAGE('At %1 Location for Item %2',ItemRec."Location Filter",ItemRec."No.");
    END;
    ItemRec.CALCFIELDS("Qty. on Purch. Order");
    CalcifieldVar := ItemRec."Qty. on Purch. Order";
    IF CalcifieldVar >= PurchaseQuantityRequired THEN BEGIN
    MESSAGE('For this Item %1 Quantity on purchase order is %2',TransferLine."Item No",ItemRec."Qty. on Purch. Order");
    PurchuOrder.SETRANGE(PurchuOrder."Location Code",TransferLine."Warehouse Location");
    PurchasableQuantityRecvdHre := 0;

    IF PurchuOrder.FINDSET THEN REPEAT
    CLEAR(CodePurchaseOrder);
    QuantityRcvAtPurchuLine:= 0;
    PurchuLine.RESET;
    PurchuLine.SETRANGE(PurchuLine."Document No.",PurchuOrder."No.");
    PurchuLine.SETRANGE(PurchuLine."No.",TransferLine."Item No");

    IF PurchuLine.FINDFIRST AND ((PurchuLine.Quantity - PurchuLine."Quantity Received")<>0) THEN BEGIN
    PurchasableQuantityRecvdHre := PurchasableQuantityRecvdHre + PurchuLine.Quantity - PurchuLine."Quantity Received";
    QuantityRcvAtPurchuLine := PurchuLine.Quantity - PurchuLine."Quantity Received";
    PurchuLine.VALIDATE(PurchuLine."Qty. to Receive",QuantityRcvAtPurchuLine);
    PurchuLine.MODIFY;
    PurchuOrder.Receive := TRUE;
    PurchuOrder.Invoice := FALSE;
    PurchuOrder.MODIFY;
    CodePurchaseOrder.RUN(PurchuOrder);

    MESSAGE('%1%2',PurchasableQuantityRecvdHre,PurchaseQuantityRequired)
    END;
    UNTIL (PurchasableQuantityRecvdHre >= PurchaseQuantityRequired) AND (PurchuOrder.NEXT = 0);

    END;
    UNTIL TransferLine.NEXT = 0;
  • SuDSuD Member Posts: 102
    Kishorm wrote: »
    It's likely because of this line...
    UNTIL (PurchasableQuantityRecvdHre >= PurchaseQuantityRequired) AND (PurchuOrder.NEXT = 0);
    
    ...are you sure it's not supposed to be...
    UNTIL (PurchasableQuantityRecvdHre >= PurchaseQuantityRequired) OR (PurchuOrder.NEXT = 0);
    

    Yes..u r right..thank you
  • KishormKishorm Member Posts: 921
    Reading the code again, I'm 100% certain that it should be an OR instead of an AND - change it and it will fix your infinite loop problem :)
Sign In or Register to comment.