TOPN

TOPN( recordset, count, sorts [, BEST( bestvalues ) ] [,LOCAL] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

recordsetThe set of records to process. This may be the name of a dataset or a record set derived from some filter condition, or any expression that results in a derived record set.
countAn integer expression defining the number of records to return.
sortsA comma-delimited list of expressions or key fields in the recordset on which to sort, with the leftmost being the most significant sort criteria. A leading minus sign (-) indicates a descending-order sort on that element. You may use the keyword RECORD to indicate an ascending sort on all fields, and/or you may use the keyword EXCEPT to list non-sort fields in the recordset.
BESTOptional. Allows early termination of the operation if there are count number of records and the values contained in the last record match the bestvalues.
bestvaluesA comma delimited list, matching the list of sorts, of maximum (or minimum if the corresponding sort is descending) values.
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:TOPN returns a set of records.

The TOPN function returns the first count number of records in the sorts order from the recordset. This is roughly equivalent to CHOOSEN(SORT(recordset,sorts),count) but with simpler syntax. This also returns the top number of rows in each group of GROUPed recordsets and local operations.

Example:

y := TOPN(Person,1000,state,sex);     //first 1000 recs in state, sex order
z := TOPN(Person,1000,sex,BEST('F')); //first 1000 females

See Also: CHOOSEN, SORT, GROUP