Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

Parameters by value and by reference

Helper(nValue); Helper(@nValue)

Distinguishes scalar value passing from caller-variable updates.

Parameters by value and by referenceAdvPL
01 · OVERVIEW

Overview

In a normal call, assigning a new number to a parameter does not replace the caller’s numeric variable. With @ at the call site, the function can update that variable by reference. Arguments are positional rather than matched by local names. This example uses only a scalar to isolate the distinction. Arrays and objects need additional shared-content analysis; passing a container does not independently copy every element. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

Helper(nValue); Helper(@nValue)
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed570()
    Local nValue := 10
    // Only the second call can update the caller variable.
    IncrementValue(nValue)
    ConOut(cValToChar(nValue))
    IncrementValue(@nValue)
    ConOut(cValToChar(nValue))
Return Nil

Static Function IncrementValue(nValue)
    nValue := nValue + 1
Return nValue
Expected result

After value call: 10. After reference call: 11. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Document mutable arguments and validate types before calculation. Avoid hidden effects and do not pass constants as output variables.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Programação em ADVPL — treinamento histórico, operador @, p. 7. Accessed on 2026-10-27.
  2. TOTVS. Programação em ADVPL I P10 — passagem de parâmetros entre funções, material histórico. Accessed on 2026-10-27.
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