GROUP

GROUP( recordset [, breakcriteria [, ALL ] ] [, LOCAL ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

recordsetThe set of records to fragment.
breakcriteriaOptional. A comma-delimited list of expressions or key fields in the recordset that specifies how to fragment the recordset. You may use the keyword RECORD to indicate all fields in the recordset, and/or you may use the keyword EXCEPT to list non-group fields in the structure. You may also use the keyword ROW to indicate each record in the recordset is a separate group. If omitted, the recordset is ungrouped from any previous grouping.
ALLOptional. Indicates the breakcriteria is applied without regard to any previous order. If omitted, GROUP assumes the recordset is already sorted in breakcriteria order.
LOCALOptional. Specifies the operation is performed on each supercomputer node independently, without requiring interaction with all other nodes to acquire data; the operation maintains the distribution of any previous DISTRIBUTE.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.
Return:GROUP returns a record set.

The GROUP function fragments a recordset into a set of sets. This allows aggregations and other operations (such as ITERATE, DEDUP, ROLLUP, SORT and others) to occur within defined subsets of the data--the operation executes on each subset, individually. This means that the boundary condition code written in the TRANSFORM function for those functions that use them will be different than it would be for a recordset that has simply been SORTed.

The recordset must be sorted by the same elements as the breakcriteria if the ALL option is not specified.

The recordset gets 'ungrouped' by use in a TABLE function, by the JOIN function in some circumstances (see JOIN), by UNGROUP, or by another GROUP function with the second parameter omitted.

Example:

MyRec := RECORD
 STRING20 Last;
 STRING20 First;
END;
SortedSet := SORT(Person,Person.last_name); //sort by last name
GroupedSet := GROUP(SortedSet,last_name);  //then group them

SecondSort := SORT(GroupedSet,Person.first_name);
   //sorts by first name within each last name group
   // this is a "sort within group"

UnGroupedSet := GROUP(GroupedSet); //ungroup the dataset
MyTable := TABLE(SecondSort,MyRec); //create table of sorted names

See Also: REGROUP, COMBINE, UNGROUP, EXCEPT