aVetorArray to sort.
AdvPL GuideASort( <aVetor>, [nInicio], [nCont], [bOrdem] ) --> aRetornoSorts an array or range with an optional comparator.
ASort changes the array itself and returns its reference. Default order is ascending for comparable element types. For matrices its block receives two elements and indicates whether the first precedes the second. Documentation does not guarantee stable ordering of ties; add a tie-breaker when required. The comparator may run many times and must not write data or modify compared elements. (TOTVS, s.d., ref. 1)
ASort( <aVetor>, [nInicio], [nCont], [bOrdem] ) --> aRetornoaVetorArray to sort.
nInicioStart; default 1.
nContCount; default through the end.
bOrdemComparator receiving two elements.
Reference to the sorted array.
#Include "Protheus.ch"
User Function EdAsort()
Local aItems := {{"B", 20}, {"A", 10}}
// Compare the text key without modifying records.
ASort(aItems, , , {|aLeft, aRight| aLeft[1] < aRight[1]})
ConOut(aItems[1][1])
Return NilExpected first key: A. The original collection is reordered. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.