DataBasic Reference > Statements and Intrinsic Functions > S > SORT Function

Comment on this topic

Documentation Comments

Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.

Reality V15.0 ()

SORT Function (DataBasic) (m618703+sort_f.htm)

To

Reality

Version

Topic

Submitted by

Company

Location

Email address

Comment

 

 

SORT Function

Sorts the contents of a dynamic array.

Syntax

SORT(array{, attr#{, value# {, sortOrder}}})

SORT(array{, attr#{, value#}}; sortOrder)

Syntax Elements

array Any DataBasic expression that evaluates to a dynamic array.

attr# Optional. The number of the attribute to sort.

value# Optional. The number of the value to sort within the specified attribute.

sortOrder Optional. Any DataBasic expression that evaluates to a string containing a combination of the following letters:

[A || D][L || R]{N}{[S || I]}

where the letters have the following meanings:

[A || D] Sort into ascending/descending order respectively.

[L || R] Sort into ASCII/numeric order respectively.

N Preserve null fields.

[S || I] Case sensitive/insensitive respectively. If omitted, the current case sensitivity setting (set with the CASING statement or at TCL with the CASE command) is used.

Note that you do not need to enable data case-insensitivity to use these options.

The default sort order is "AL".

Note: This parameter can be in any combination of upper and lower case.

Return Value

The return value is a dynamic array containing the selected elements, sorted as specified and separated by attribute marks.

Note: Before sorting, all values and sub-values in the selected elements are promoted to attributes.

Unless the N sort order option is specified, all null elements are removed.

Comments

If attr# and/or value# are omitted, but sortOrder is included, array must be separated from sortOrder with a semicolon. If a comma is used, an error will be generated at runtime.

Examples

SORTED = SORT(UNSORTED)

Sorts the array UNSORTED into ascending ASCII order and assigns the result to the variable SORTED.

DR = SORT(X; "DR")

Sorts the array X into descending numeric order and assigns the result to the variable DR. Note the semicolon separating the two parameters; this is necessary because no attribute and value are specified.

AL3 = SORT(ARY, 3)

Sorts the third attribute of array ARY into ascending ASCII order and assigns the sorted elements to the variable AL3.

AL23 = SORT(ARY, 3, 2, "DLI")

Sorts the second value of the third attribute of array ARY into descending ASCII order, ignoring case and assigns the sorted elements to the variable AL23.

RealityV15.0Comment on this topic