This is something I used when summing totals whilst filtering on Posting Groups… strip out these bits out and should work.
recGLEntry.RESET;
recGLEntry.SETCURRENKEY(...); // try to get a key that can be used to
find the filtered data in a fast way
recGLEntry.SETRANGE(.....); // put your filters
IF recGLEntry.FINDSET THEN
REPEAT
// "tmpGLEntry" is the temptable we will use to store the grouping
totals
tmpGLEntry.RESET;
// try to get a good key for the filters
IF NOT tmpGLEntry.SETCURRENTKEY("Gen. Bus. Posting Group") THEN
IF NOT tmpGLEntry.SETCURRENTKEY("Gen. Prod. Posting Group") THEN ;
// I filter on the records for which I want to group the records
tmpGLEntry.setrange("Gen. Bus. Posting Group",recGLEntry."Gen. Bus.
Posting Group");
tmpGLEntry.setrange("Gen. Prod. Posting Group",recGLEntry."Gen. Prod.
Posting Group");
IF NOT tmpGLEntry.FINDFIRST THEN BEGIN
// I didn't find a record, so I have to create a new one.
// Remember that to insert a record, you have to respect a unique
primary key.
// This is done, because EACH "recGLEntry" I read is unique, so I
can just insert
// "recGLEntry" in my temptable.
tmpGLEntry := recGLEntry;
tmpGLEntry.insert(FALSE);
END
ELSE BEGIN
// I found the record with combination I wanted, so I add the
field(s) I am SUMming
tmpGLEntry.Amount += recGLEntry.Amount;
tmpGLEntry.MODIFY(FALSE);
END;
UNTIL recGLEntry.NEXT = 0;
// In the temptable I now have records that contain the SUM for the
combination I wanted.
// Now you can just read the temptable and do what you want to do with
your totals
tmpGLEntry.RESET;
FORM.RUNMODAL(0,tmpGLEntry);