Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

AIns

AIns( <aDest>, <nPos> ) --> aRet

Inserts a Nil slot without growing the array.

AInsAdvPL
01 · OVERVIEW

Overview

AIns shifts elements forward and discards the last while keeping Len unchanged. To preserve the final element, grow the array before inserting and assign the new content into the created slot. The example reserves space with ASize. Insertion changes indexes, so refresh dependent selections afterward. (TOTVS, s.d., ref. 1)

02 · SYNTAX

Syntax

AIns( <aDest>, <nPos> ) --> aRet

Parameters

aDest
ArrayRequired

Array to modify.

nPos
NumericRequired

Insertion position starting at 1.

Return value

Array after insertion.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function EdAins()
    Local aItems := {"A", "C"}
    // Reserve a slot to avoid discarding C.
    ASize(aItems, Len(aItems) + 1)
    AIns(aItems, 2)
    aItems[2] := "B"
    ConOut(aItems[3])
Return Nil
Expected result

Expected array: {"A", "B", "C"}; output C. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Validate the position after sizing. Use AAdd to express simple append operations more clearly.
  • 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-25.
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