User Tools

Site Tools


sort_sort_queue_entries_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== SORT (sort queue entries) ====== Previous pageReturn to chapter overviewNext page
SORT( queue, [+]key,…,[-]key] )
name
function

blk2blue.jpg

SORT Reorders entries in a QUEUE.
queue The label of a QUEUE structure, or the label of a passed QUEUE parameter.
+ - The leading plus or minus sign specifies the key will be sorted in ascending or descending sequence.
key The label of a field declared within the QUEUE structure. If the QUEUE has a PRE attribute, the key must include the prefix. This may not be a reference variable.
name A string constant, variable, or expression containing the NAME attribute of QUEUE fields, separated by commas, and optional leading + or - signs for each attribute. This parameter is case sensitive and may not contain any reference variables.
function The label of the function containing two parameters of a *GROUP or named GROUP passed by address, and having a SIGNED return value. Both parameters must use the same parameter type, and cannot be omitted. The RAW, C and PASCAL attributes are not permitted in the prototype declaration. See Additional Queue Considerations.

SORT reorders the entries in a QUEUE. QUEUE entries with identical key values maintain their relative position.

SORT(queue,key) Reorders the QUEUE in the sequence specified by the key. Multiple key parameters may be used (up to 16), separated by commas, with optional leading plus or minus signs to indicate ascending or descending sequence.
SORT(queue,name) Reorders the QUEUE in the sequence specified by the name string. The name string must contain the NAME attributes of the fields, separated by commas, with leading plus or minus signs to indicate ascending or descending sequence.

Errors Posted:

08 Insufficient Memory
75 Invalid Field Type Descriptor

Example:

Location  QUEUE,PRE(Loc)

Name       STRING(20),NAME('FirstField')

City       STRING(10),NAME('SecondField')

State      STRING(2)

Zip        DECIMAL(5,0)

         END

CODE

SORT(Location,Loc:State,Loc:City,Loc:Zip)    !Sort by zip in city in state

SORT(Location,+Loc:State,-Loc:Zip)           !Sort descending by zip in state

SORT(Location,'FirstField,-SecondField')     !Sort descending by city in name

!Example of using SORT with a FUNCTION as a parameter PROGRAM MAP  CaseInsensitive(*GROUP A, *GROUP B),SIGNED end Q      QUEUE Val      STRING(5)       END Window WINDOW('Test Sort'),AT(,,116,224),FONT('MS SansSerif',8,,FONT:regular),IMM,SYSTEM,GRAY,AUTO       BUTTON('Sort Case Sensitive'),AT(8,3,95,14),USE(?SortCase),LEFT,DEFAULT       BUTTON('Sort Case INSensitive'),AT(8,20,95,14),USE(?SortNoCase),LEFT       LIST,AT(6,37,101,179),USE(?List1),FORMAT('7L(2)|M~Val~@s5@'),FROM(Q)     END CODE Q.Val = 'aaaaa'; Add(Q) Q.Val = 'AAAAA'; Add(Q) Q.Val = 'ddddd'; Add(Q) Q.Val = 'DDDDD'; Add(Q) Q.Val = 'EEEEE'; Add(Q) Q.Val = 'eeeee'; Add(Q) Q.Val = 'qqqqq'; Add(Q) Q.Val = 'QQQQQ'; Add(Q) Q.Val = 'zzzzz'; Add(Q) Q.Val = 'ZZZZZ'; Add(Q) Q.Val = 'ggggg'; Add(Q) Q.Val = 'GGGGG'; Add(Q) OPEN(Window) ACCEPT   CASE ACCEPTED()     OF ?SortCase   ; SORT(Q, Q.Val)     OF ?SortNoCase ; SORT(Q, CaseInsensitive)   END END CaseInsensitive PROCEDURE(*GROUP A, *GROUP B)!,SIGNED CODE IF UPPER(A) = UPPER(B)  RETURN  0 ELSIF UPPER(A) > UPPER(B)  RETURN  1 ELSE  RETURN -1 END See Also:**

ADD

GET

PUT

sort_sort_queue_entries_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1