procedure TempRecordGroupMethod()
var
RecordToGroup: Record "RecordToGroup";
TempRecordToGroupResult: Record "RecordToGroup" temporary;
GroupNo: Integer;
begin
RecordToGroup.SetCurrentKey(GroupField1, GroupField2, ..., GroupField999);
if RecordToGroup.FindSet() then
repeat
//Check if group is exist
TempRecordToGroupResult.SetRange(GroupField1, RecordToGroup.GroupField1);
TempRecordToGroupResult.SetRange(GroupField2, RecordToGroup.GroupField2);
...
TempRecordToGroupResult.SetRange(GroupField999, RecordToGroup.GroupField999);
if not TempRecordToGroupResult.FindFirst() then begin
//New group record initialization
GroupNo += 1;
TempRecordToGroupResult := RecordToGroup;
TempRecordToGroupResult.Insert();
end else begin
//Continuation of the group
//here you can update values for group, maybe sum some amounts, etc.
TempRecordToGroupResult.Amount += RecordToGroup.Amount;
TempRecordToGroupResult.Modify();
end;
until RecordToGroup.Next() = 0;
end;
procedure SalesLineTempRecordGroupMethod()
var
SalesLine: Record "Sales Line";
TempSalesLineResult: Record "Sales Line" temporary;
GroupNo: Integer;
begin
SalesLine.SetCurrentKey("Sell-to Customer No.", Type, "No.");
if SalesLine.FindSet() then
repeat
//Check if group is exist
TempSalesLineResult.SetRange("Sell-to Customer No.", SalesLine."Sell-to Customer No.");
TempSalesLineResult.SetRange(Type, SalesLine.Type);
TempSalesLineResult.SetRange("No.", SalesLine."No.");
if not TempSalesLineResult.FindFirst() then begin
//New group record initialization
GroupNo += 1;
TempSalesLineResult := SalesLine;
TempSalesLineResult.Insert();
end else begin
//Continuation of the group
//here you can update values for group, maybe sum some amounts, etc.
TempSalesLineResult.Amount += SalesLine.Amount;
TempSalesLineResult.Modify();
end;
until SalesLine.Next() = 0;
end;
query 50000 "Query Group Method"
{
Caption = 'Query Group Method';
QueryType = Normal;
OrderBy = ascending(FieldToGroup1, FieldToGroup2, ... ,FieldToGroup999);
elements
{
dataitem(RecordToGroup; "RecordToGroup")
{
column(FieldToGroup1; FieldToGroup1)
{
}
column(FieldToGroup2; FieldToGroup2)
{
}
...
column(FieldToGroup999; FieldToGroup999)
{
}
column(Amount; Amount)
{
Method = Sum;
}
}
}
}
procedure QueryMethod()
var
QueryGroupMethod: Query "Query Group Method";
DictOfGroup: Dictionary of [Integer, Decimal];
GroupNo: Integer;
begin
QueryGroupMethod.Open();
while QueryGroupMethod.Read() do begin
//New group per read, store sum of amount in dictionary
GroupNo += 1;
DictOfGroup.Add(GroupNo, QueryGroupMethod.Amount);
end;
end;
query 50000 "Sales Line Group Method"
{
Caption = 'Sales Line Group Method';
QueryType = Normal;
OrderBy = ascending(SelltoCustomerNo, "Type", No);
elements
{
dataitem(SalesLine; "Sales Line")
{
column(SelltoCustomerNo; "Sell-to Customer No.")
{
}
column("Type"; "Type")
{
}
column(No; "No.")
{
}
column(Amount; Amount)
{
Method = Sum;
}
}
}
}
procedure SalesLineQueryGroupMethod()
var
SalesLineGroupMethod: Query "DAT Sales Line Group Method";
DictOfGroup: Dictionary of [Integer, Decimal];
GroupNo: Integer;
begin
SalesLineGroupMethod.Open();
while SalesLineGroupMethod.Read() do begin
//New group per read, store sum of amount in dictionary
GroupNo += 1;
DictOfGroup.Add(GroupNo, SalesLineGroupMethod.Amount);
end;
end;
procedure FilterMethod()
var
RecordToGroup: Record RecordToGroup;
ResultGroupedRecord: Record ResultGroupedRecord temporary;
GroupFilter1, GroupFilter2, ... , GroupFilter999: text;
GroupNo: integer;
begin
//Get default filters (list of fields from grouping)
GroupFilter1 := RecordToGroup.GetFilter("FieldToGroup1");
GroupFilter2 := RecordToGroup.GetFilter("FieldToGroup2");
...
GroupFilter999 := RecordToGroup.GetFilter("FieldToGroup999");
RecordToGroup.SetCurrentKey(FieldToGroup1, FieldToGroup2, ...., FieldToGroup999);
if RecordToGroup.FindSet() then
repeat
//Set current group filters
RecordToGroup.SetRange(FieldToGroup1, RecordToGroup.FieldToGroup1);
RecordToGroup.SetRange(FieldToGroup2, RecordToGroup.FieldToGroup2);
...
RecordToGroup.SetRange(FieldToGroup999, RecordToGroup.FieldToGroup999);
//Go to last record of group
RecordToGroup.FindLast();
//New group, calc amount and put it to dictionary
GroupNo += 1;
RecordToGroup.CalcSums(Amount);
DictOfGroup.Add(GroupNo, RecordToGroup.Amount);
//Set default filters
RecordToGroup.SetFilter(FieldToGroup1, GroupFilter1);
RecordToGroup.SetFilter(FieldToGroup2, GroupFilter2);
...
RecordToGroup.SetFilter(FieldToGroup999, GroupFilter999);
until RecordToGroup.Next() = 0;
end;
procedure FilterMethod()
var
RecordToGroup: Record RecordToGroup;
ResultGroupedRecord: Record ResultGroupedRecord temporary;
GroupFilter1, GroupFilter2, ... , GroupFilter999: text;
GroupNo: integer;
begin
//Get default filters (list of fields from grouping)
GroupFilter1 := RecordToGroup.GetFilter("FieldToGroup1");
GroupFilter2 := RecordToGroup.GetFilter("FieldToGroup2");
...
GroupFilter999 := RecordToGroup.GetFilter("FieldToGroup999");
RecordToGroup.SetCurrentKey(FieldToGroup1, FieldToGroup2, ...., FieldToGroup999);
if RecordToGroup.FindSet() then
repeat
//Set current group filters
RecordToGroup.SetRange(FieldToGroup1, RecordToGroup.FieldToGroup1);
RecordToGroup.SetRange(FieldToGroup2, RecordToGroup.FieldToGroup2);
...
RecordToGroup.SetRange(FieldToGroup999, RecordToGroup.FieldToGroup999);
//Go through each record
repeat
RecordToGroup.Next() = 0;
//New group, calc amount and put it to dictionary
GroupNo += 1;
RecordToGroup.CalcSums(Amount);
DictOfGroup.Add(GroupNo, RecordToGroup.Amount);
//Set default filters
RecordToGroup.SetFilter(FieldToGroup1, GroupFilter1);
RecordToGroup.SetFilter(FieldToGroup2, GroupFilter2);
...
RecordToGroup.SetFilter(FieldToGroup999, GroupFilter999);
until RecordToGroup.Next() = 0;
end;
procedure SalesLineFilterMethod()
var
SalesLine: Record "Sales Line";
GroupNo: Integer;
FieldFilter1, FieldFilter2, FieldFilter3 : Text;
DictOfGroup: Dictionary of [Integer, Decimal];
begin
//Get default filters
FieldFilter1 := SalesLine.GetFilter("Sell-to Customer No.");
FieldFilter2 := SalesLine.GetFilter(Type);
FieldFilter3 := SalesLine.GetFilter("No.");
SalesLine.SetCurrentKey("Sell-to Customer No.", Type, "No.");
if SalesLine.FindSet() then
repeat
//Set current group filters
SalesLine.SetRange("Sell-to Customer No.", SalesLine."Sell-to Customer No.");
SalesLine.SetRange(Type, SalesLine.Type);
SalesLine.SetRange("No.", SalesLine."No.");
//Go to last record of group
SalesLine.FindLast();
//New group, calc amount and put it to dictionary
SalesLine.CalcSums(Amount);
GroupNo += 1;
DictOfGroup.Add(GroupNo, SalesLine.Amount);
//Set default filters
SalesLine.SetFilter("Sell-to Customer No.", FieldFilter1);
SalesLine.SetFilter(Type, FieldFilter2);
SalesLine.SetFilter("No.", FieldFilter3);
until SalesLine.Next() = 0;
end;
key(GroupKey; "Document Type", "Customer Name")
{
SumIndexFields = Amount;
}