xcall SORTIT, array, reccnt, recsiz, k1siz, k1pos, k1ord, k2siz, k2pos, k2ord, k3siz, k3pos, k3ord, k1typ, k2typ, k3typ, k4siz, k4pos, k4ord, k5siz, k5pos, k5ord, k6siz, k6pos, k6ord, k4typ, k5typ, k6typ
SORTIT.SBR is basically the same as BASORT, except it is used to sort arrays in memory rather than files on disk. The arguments are all analogous to those of BASORT (and therefore, hopefully, self-explanatory) and like BASORT, the default key type is string, and the parameters for the second and third keys (and types) are optional. The array argument is typically specified as the name of a MAP1 variable, under which the array is mapped, as shown here:
Like BASORT, SORTIT preserves the order of items with equal keys.
MAP1 ARY
MAP2 SRTARY(50)
MAP3 NAME,S,20
MAP3 AGE,B,2
etc.
Note that for binary sort keys, only 2 and 4 byte size is supported.
History
2009 January, A-Shell 5.1.1136: SORTIT now support the 3 new sort types (see BASORT), plus F4 and F8. Note, however, that SORTIT does not support B1 or I1 keys, and ignores the LDF collating sequence.
2008 August, A-Shell 5.1.1122: F8 and F4 keys now supported.
2006 August, A-Shell 4.9.970
SORTIT.SBR now permits the first element of an array to be sorted. Previously, you had to map the array underneath an unformatted variable like this:
MAP1 ARRAYX
MAP2 ARRAY(100)
MAP3 FLD1,S,10
etc.
The problem with requiring the ARRAYX variable (in the example above) to be passed to SORTIT.SBR is that it prevents you from sorting arrays allocated via DIMX. So now it is possible to do something like this:
DIMX ARRAY(COUNT),S,WIDTH
XCALL SORTIT,ARRAY(1),COUNT,WIDTH,K1SIZ,...
Note that in such a case, there is no way for the subroutine to verify that the ARRAY actually has COUNT elements, so you'd best be cautious lest you commit mayhem in memory.
2004 January, A-Shell 4.9.858
SORTIT.SBR now supports up to 6 sort keys.
Everything after k1ord is optional; if you specify one of the keys, you must specify the k?siz, k?pos, and k?ord arguments, but may omit the k#typ argument (in which case it defaults to 0 or string). The superceded syntax was:
xcall SORTIT, array, reccnt, recsiz, k1siz, k1pos, k1ord, k2siz, k2pos, k2ord, k3siz, k3pos, k3ord, k1typ, k2typ, k3typ