Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Arrays: creation, access, insertion, deletion and sorting

Combines array operations while distinguishing shifting, length and copying.

Arrays: creation, access, insertion, deletion and sortingAdvPL
01 · OVERVIEW

Overview

Array positions start at 1. AIns shifts elements at unchanged length and discards the last; grow first with ASize to preserve it. ADel shifts left and leaves Nil at the end without shrinking; shrink afterwards when deletion should shorten the list. The consulted ASize page documents Nil as its return, so do not assign that return to the array. ASort modifies the supplied reference; use AClone first when preserving the original structure matters. The example combines documented operations from the related pages. (TOTVS, n.d., refs. 1–5)

Return value

No single return value: this is a composite workflow.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function EdArrays()
    Local aValues := {30, 10, 20}
    Local aCopy
    // Insert without losing the last element.
    ASize(aValues, Len(aValues) + 1)
    AIns(aValues, 2)
    aValues[2] := 15
    ADel(aValues, 1)
    ASize(aValues, Len(aValues) - 1)
    aCopy := AClone(aValues)
    ASort(aCopy)
    ConOut(cValToChar(aValues[1]))
    ConOut(cValToChar(aCopy[1]))
Return Nil
Expected result

Final original {15, 10, 20}; sorted copy {10, 15, 20}; expected outputs 15 and 10. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check bounds before access. Distinguish array cloning from object copying and define a consistent comparator for heterogeneous structures.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. AIns. TDN. Accessed on 2026-10-26.
  2. TOTVS. ADel. TDN. Accessed on 2026-10-26.
  3. TOTVS. ASize. TDN. Accessed on 2026-10-26.
  4. TOTVS. AClone. TDN. Accessed on 2026-10-26.
  5. TOTVS. ASort. TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha