Previous Topic: SHOVE()Next Topic: SPAWN()


SORT()

This function to sorts records on any stack belonging to any IMOD. Up to six fields can be sorted on simultaneously, with the sorting precedence running from left to right.

Restriction

SORT() can specify a stack external to an IMOD only when the target stack has been declared public for writing.

Syntax

SORT([stack],[owner],[order,field,leng],...,[order,field,leng])

Parameters

stack

Number of the stack to be referenced.

Default: If a local stack is referenced, the current stack (as set by the SWAPSTAK() function). Otherwise, the owning IMOD task sets the value using the PUBSTACK(DEFAULT) function.

owner

IMOD ID of the owner of the stack (for external reference). This value can be obtained from the variable imod_id in the owning IMOD task. It is also the value that the SPAWN() function returns.

Default: Current IMOD task

order

Specify:

AP

An ascending sort; column number specifies the field.

DP

A descending sort; column number specifies the field.

field

Defines the start of a field. For column-specified fields (type = AP and DP), this is the column number of the start of the field.

leng

Length of a sort field. For column-specified fields (type = AP and DP), this is the number of characters in the field.

Return Codes

101 - 120

ARG n MISSING OR INVALID

122

STACK NOT SPECIFIED AND NO DEFAULT

123

SPECIFIED STACK DOES NOT EXIST

125

SPECIFIED IMOD NOT FOUND

126

STACK WRITE FAILED

127

REQUESTED STACK DOES NOT EXIST

128

SPECIFIED IMOD/STACK NOT AUTHORIZED

Example

x = sort(0,2,'AP',7,10,'AP',1,6)
                    /* Sort IMOD 2's stack 0. Sort the records
                       by the 10-character field starting in
                       column 7. Within equal records, sort on
                       the 6-character field beginning in
                       column 1. */