Doubt on FINDSET and FINDFIRST

gdkve9gdkve9 Member Posts: 161
Dear Mibusonians,

HaPPy New Year 2010 to one and all. Hope every one doing good.

The problem I am facing seems to be very basic but unable to sort it out. I need to use ASCENDING Function and as this function doesnt work with FINDSET, I have replaced the FINDSET with FINDFIRST in the code shown below.
WITH SalesPrice DO BEGIN
  //>>Dilip 27Nov2009
  //FoundSalesPrice := FINDSET;
  FoundSalesPrice := FINDFIRST;
  ASCENDING(FALSE);
  //<<Dilip 27Nov2009
  IF FoundSalesPrice THEN
    REPEAT
      IF IsInMinQty("Unit of Measure Code","Minimum Quantity") THEN BEGIN
        ConvertPriceToVAT(
          "Price Includes VAT",Item."VAT Prod. Posting Group",
          "VAT Bus. Posting Gr. (Price)","Unit Price");
        ConvertPriceToUoM("Unit of Measure Code","Unit Price");
        ConvertPriceLCYToFCY("Currency Code","Unit Price");

        CASE TRUE OF
          ((BestSalesPrice."Currency Code" = '') AND ("Currency Code" <> '')) OR
          ((BestSalesPrice."Variant Code" = '') AND ("Variant Code" <> '')):
            BestSalesPrice := SalesPrice;
          ((BestSalesPrice."Currency Code" = '') OR ("Currency Code" <> '')) AND
          ((BestSalesPrice."Variant Code" = '') OR ("Variant Code" <> '')):
            IF (BestSalesPrice."Unit Price" = 0) OR
               (CalcLineAmount(BestSalesPrice) > CalcLineAmount(SalesPrice))
            THEN
              BestSalesPrice := SalesPrice;
        END;
      END;
    UNTIL NEXT = 0;
END;
This code is in Codeunit 7000 Sales Price Calc. Mgt.\CalcBestUnitPrice(SalesPrice).

Here my problem is if I use FINDSET, the loop for REPEAT..UNTIL works (as I have defined multiple prices for a specific customer and specific item with varying price on different Minimum Qty), but the same doesnt work for FINDFIRST.

Kindly suggest proper method where is I can be able to use the ASCENDING function and also the REPEAT..UNTIL loop works in the above mentioned case.

Awaiting for your earliest suggestions. Thanks in advance to all.
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.

Answers

  • AlbertvhAlbertvh Member Posts: 516
    Hi Dilip,

    As your sorting is DESCENDING you UNTIL NEXT = 0; statement should be NEXT(-1) = 0;

    Hope this helps.

    Albert
  • gdkve9gdkve9 Member Posts: 161
    Thanks a lot Albert.

    I just missed my focus at that line of Next = 0;

    Yes, As I am desending the sort, Next(-1) = 0 should be the condition to add it there. It works fine now.

    Thanks again.
    Dilip
    Falling down is not a defeat..defeat is when you refuse to get up.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Why do you want to do this?

    This loop finds the best sales price and IMHO it does not matter if you start at the bottom or beginning.

    Just Curious.

    Oh, and change the FINDFIRST to a FIND('-') please.
  • krikikriki Member, Moderator Posts: 9,110
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.