A few days ago, I got requirement, where I have to sum up the total quantity and amount of all Purchase line. Here we assume that All lines in Purchase order belongs to same set or convertible unit.
You can set these unit conversion settings at
Organization administration > Setup > Units > Unit conversions.
Public void SumQTYAndAmount(PurchTable PurchTable) { PurchLine line; UnitOfMeasureSymbol toSymbol ="Ranjah"; UnitOfMeasureSymbol fromSymbol; Qty SumQty=0; AmountCur AmountPurch=0; UnitOfMeasureRecId fromRecid,toRecid; ; select * from plan where plan.PurchTable == PurchTable.PurchId; // select sum(LineAmount), sum(QtyOrdered) from line where line.PurchId == PurchTable.PurchId; while select * from LineQty where LineQty.PurchId == PurchTable.PurchId { if ( LineQty.PurchUnit ==toSymbol) { SumQty +=LineQty.QtyOrdered; amountQty+=LineQty.LineAmount; } else { fromSymbol = LineQty.PurchUnit; toRecid =UnitOfMeasure::findBySymbol(toSymbol).RecId; fromRecid =UnitOfMeasure::findBySymbol(fromSymbol).RecId; landQty += UnitOfMeasureConverter::convert(landQty,fromRecid,toRecid,NoYes::Yes); amountQty+=LineQty.LineAmount; } } }