FundLots.DBF (fields) cLot_Numb c(4) && Lot sequence FI = low number LI = higest number cLot_Stat c(1) && '1' for shares available, '0' for no shares (depeleted) cFundName c(6) && Example 'AAAA' nOrigShare n(10) && Original Shares Purchased nBalnShare n(10) && Current shares (these may have decimals) nPricShare n(10,4) && Price per share at purchase && Would be used to weight the cost (average cost) && of purchase Index on cLot_Stat+cFundName+cLot_Numb tag LotPullOrder * Now some sample INTIAL data (I won't use all the fields) x LotPullOrder cLot_Stat cFundName cLot_Numb nBalnShare 0 AAAA 1 0 1 AAAA 2 1000 1 AAAA 3 1000 1 AAAA 4 300 * Now lets pull 1500 shares of Fund 'AAAA' nSellShares=1500 && Total shares to be pulled from lots nPulledShares=0 && Accumulated shares pulled SET EXACT OFF && want to ignore required (sequencing/FIFO) cLot_Numb field IF SEEK("1"+"AAAA ","FundLots","LotPullOrder") SET EXACT ON * Process this lots to accrued nSellShares DO WHILE !EOF("FundLots") AND FundLots.cFundName="AAAA " * nNeededShares is working pulled balance forward nNeededShares = nSellShares - nPulledShares IF FundLots.nBalnShare >= nNeededShares nPulledShares = nPulledShares + nNeededShares REPLACE nBalnShare with nBalnShare - nNeededShares ; IN FundLots * Write this lot's shares to a transaction file ELSE && Not enough available shares in FundLots.nBalnShare nPulledShares=nPulledShares+FundLots.nBalnShare REPLACE FundLots.nBalnShare with 0 * Write this lot's shares to a transaction file ENDIF &&FundLots.nBalnShare >= nNeededShares IF FundLots.nBalnShare = 0 REPLACE cLot_Stat with '0' in FundLots ENDIF &&FundLots.nBalnShare = 0 IF nPulledShares=nSellShares EXIT &&!EOF("FundLots") and FundLots.cFundName="AAAA " ENDIF SKIP IN FundLots ENDDO &&WHILE !EOF("FundLots") and FundLots.cFundName="AAAA " IF nPulledShares=nSellShares * Enough shares pulled ELSE * Not enough shares pulled ENDIF &&nPulledShares=nSellShares ELSE && SEEK FAILED SET EXACT ON ENDIF &&SEEK("1"+"AAAA ","FundLots","LotPullOrder") * Resulting Quantities in FundLots.DBF cLot_Stat cFundName cLot_Numb nBalnShare 0 AAAA 1 0 0 AAAA 2 0 && Not cLot_Stat='0' 1 AAAA 3 500 1 AAAA 4 300 * In the sections replacing FundLots.nBalnShare, you * would write one record each for each lot contribution * to the accumulation of shares to be sold. * The trick is setting cLot_Stat to 0 when all shares * for lot are depleted.>New lots are created for each fund purchase. If I purchase fund AAA three times over a period. Three new lots are created. Then when there is a sales transaction. They want to see which fund(s) the sale came from. It is assumed that there will never be more sold than there is on hand.