Delete All Records - Temporary Table

leikelmanleikelman Member Posts: 31
I am using a temporary table in one of my reports. The temporary table is pointing to a new table that we created, that has no custom table level CAL code.

At a point in my report I need to clear all the values from my table but I can't seem to get this to work. I've tried the following:

1. Calling the DELETEALL method
2. Looping through each record and calling the DELETE function

Is the problem that I am using a custom table we created or is there some other way of deleting record from a temp. table I am not familiar with?

Thank you,

Leo

Comments

  • DaveTDaveT Member Posts: 1,039
    Hi Leo,

    TempRec.DELETEALL;

    should work.

    Can you post your code?
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • leikelmanleikelman Member Posts: 31
    This is a portion of my code:

    TEMP_DTLotQuantities.DELETEALL;

    DTLotQuantitiesCnt := 1;
    DTQuantityRemaining := Quantity;

    ItemLedgerEntry.INIT;

    ItemLedgerEntry.SETRANGE("Item No.",ItemNo);
    ItemLedgerEntry.SETRANGE("Item Tracking",ItemLedgerEntry."Item Tracking"::"Lot No.");
    ItemLedgerEntry.SETFILTER("Lot No.",'<>%1','');
    ItemLedgerEntry.SETFILTER("Remaining Quantity",'>0');

    IF ItemLedgerEntry.FIND('-') THEN REPEAT

    TEMP_DTLotQuantities.SETRANGE(RefERPNo,ItemLedgerEntry."Lot No.");

    IF TEMP_DTLotQuantities.FIND('-') THEN
    BEGIN
    TEMP_DTLotQuantities.DTID := TEMP_DTLotQuantities.DTID + ItemLedgerEntry."Remaining Quantity";
    TEMP_DTLotQuantities.MODIFY;
    END
    ELSE
    BEGIN
    TEMP_DTLotQuantities.ID := DTLotQuantitiesCnt;
    TEMP_DTLotQuantities.RefERPNo := ItemLedgerEntry."Lot No.";
    TEMP_DTLotQuantities.DTID := ItemLedgerEntry."Remaining Quantity";
    TEMP_DTLotQuantities.INSERT;
    DTLotQuantitiesCnt := DTLotQuantitiesCnt + 1;
    END;

    UNTIL ItemLedgerEntry.NEXT = 0;


    This is being called inside of a function that is called multiple times in the report, which is why I need to delete all records in the temporary table (TEMP_DTLotQuantities) every time. I get an error "ID '1' Already exists" when calling this function multiple times.

    Thanks.
  • DaveTDaveT Member Posts: 1,039
    Hi Leo,

    On the face of it the code looks fine. What's the key of the temp table?

    Have you used the debugger to see where the error occurs?
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • kinekine Member Posts: 12,562
    Use the TEMP_DTLotQuantities.RESET before deleteall, else you can have some filters from previous run etc. if the variable is global...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DaveTDaveT Member Posts: 1,039
    Good spot Kamil :oops:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.