Announcements
Hi everyone,
I'm still struggling with C SIDE language.
I need to calculate the total stock value of the item table and already got the total stock for each product from the item ledger entry.
Now I need the grand total of all products, how I can sum all totals from each product to get the grand total?
This is my code.
//>> calculate total stock quantity per item no.
CLEAR(TotalStockQty);
ItemLedgerEntry.SETFILTER("Item No.",Item."No.");
ItemLedgerEntry.CALCSUMS(Quantity);
TotalStockQty:= ItemLedgerEntry.Quantity;
// << calculate total stock quantity per item no.
// now sum (TotalStockQty * ItemUnitCost."Unit Cost")
CLEAR(i);
CLEAR(TotalStockValue);
ItemUnitCost.SETRANGE("No.",Item."No.");
IF ItemUnitCost.FINDSET THEN BEGIN
REPEAT
TotalStockValue += (TotalStockQty * ItemUnitCost."Unit Cost");
UNTIL ItemUnitCost.NEXT =0;
END
Thanks for any advice.
Thanks, I tried this code, it works for grand total but then the current value for each product will be showed as 0 in my report.
I guess it has something to do with the following reset statement "ItemLedgerEntry.Reset".
Hi, try this?
begin CLEAR(TotalStockValue); Item.Reset(); if Item.FindSet() then repeat //>> calculate total stock quantity per item no. CLEAR(TotalStockQty); ItemLedgerEntry.Reset(); ItemLedgerEntry.SETFILTER("Item No.", Item."No."); ItemLedgerEntry.CALCSUMS(Quantity); TotalStockQty := ItemLedgerEntry.Quantity; // << calculate total stock quantity per item no. // now sum (TotalStockQty * ItemUnitCost."Unit Cost") TotalStockValue = (TotalStockQty * Item."Unit Cost"); until Item.Next() = 0; end;
Hope this will help.
Thank.
ZHU
André Arnaud de Cal...
294,161
Super User 2025 Season 1
Martin Dráb
232,942
Most Valuable Professional
nmaenpaa
101,158
Moderator