Accumulate Function - Help

Richhsp

New Member
Hi,

I have the below code, which I am using for a customer and I need to make an addition, which uses the accumulate function. However I’m unsure how to get it to work. What I want to do is add the value of the InvcDtl.ExtPrice and InvcTax.TaxAmt and display this amount as a field in the excel spreadsheet.

If anyone has any suggestions it would be really appreciated

Thanks

Richard

DEFINE VARIABLE i-group AS CHARACTER INITIAL "".
DEFINE VARIABLE i-company AS CHARACTER INITIAL "".
DEFINE VARIABLE i-com AS CHARACTER INITIAL "".

/* 1 */

FORM "Enter The Current Company ID." i-company at 20
SKIP "Enter The Group ID Of The Invoices To Be Sent To Pegasus." i-group at 20
WITH FRAME TEST-FRAME CENTERED NO-LABELS VIEW-AS DIALOG-BOX.

/* 2 */

UPDATE i-company i-group WITH FRAME TEST-FRAME.
HIDE FRAME TEST-FRAME.

/* 3 */

OUTPUT TO c:\custbal.xls.

FOR EACH InvcHead, EACH InvcDtl WHERE InvcHead.Company = InvcDtl.Company
AND InvcHead.InvoiceNum = InvcDtl.InvoiceNum AND InvcHead.GroupID = i-group AND InvcHead.Posted = no AND InvcHead.Company = i-company,
EACH Terms WHERE Terms.Company = i-company AND InvcHead.TermsCode = Terms.TermsCode,
EACH ProdGrup WHERE ProdGrup.Company = i-company AND ProdGrup.ProdCode = InvcDtl.ProdCode,
EACH Customer WHERE Customer.Company = i-company AND InvcHead.CustNum = Customer.CustNum,
EACH ShipTo WHERE ShipTo.Company = i-company AND InvcDtl.CustNum = ShipTo.CustNum AND InvcDtl.ShipToNum = ShipTo.ShipToNum,
EACH InvcTax WHERE InvcTax.Company = i-company AND InvcHead.InvoiceNum = InvcTax.InvoiceNum AND InvcDtl.InvoiceLine = InvcTax.InvoiceLine:
PUT Customer.Character01 CHR(9)
InvcDtl.ShipToNum CHR(9)
InvcHead.InvoiceDate CHR(9)
InvcHead.InvoiceNum CHR(9)
InvcHead.PONum CHR(9)
InvcHead.CreditMemo CHR(9)
ProdGrup.Description CHR(9)
InvcDtl.ExtPrice CHR(9)
InvcTax.TaxCode CHR(9)
InvcTax.TaxAmt CHR(9)
InvcDtl.OurShipQty CHR(9)
Terms.DiscountDays CHR(9)
Terms.DiscountPercent CHR(9)
Terms.DiscountDays CHR(9)
Terms.DiscountPercent SKIP.
END.

OUTPUT CLOSE.
 
I'm fairly sure you don't want to use the accumulate function. Its main use is to provide totals and counts for a range of records.
e.g.
FOR EACH InvcTax:
ACCUMULATE InvcTax.TaxAmt(TOTAL).
END.
DISPLAY (ACCUM TOTAL InvcTax.TaxAmt).

From what I am reading, you need only define a variable, set it as the total of the two required fields and then export it in your list.
e.g.
DEF VAR fTotal AS DECIMAL NO-UNDO.
FOR EACH InvcHead, ........:
ASSIGN fTotal = InvcDtl.ExtPrice + InvcTax.TaxAmt .
PUT Customer.Character01 CHR(9)
....
fTotal CHR(9)
...
END.

As an extra pointer, your program will run faster if you use NO-LOCK on the tables you are accessing in the FOR EACH statement.

Hope this helps
 
Norman,

Thanks for your help i give that a try, sounds good i was starting to think a variable was the way to go.

Thanks again

Richhsp
 
Back
Top