Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

PUBLIC

PUBLIC xVariavel := xValor

Declares state that can persist in the thread.

PUBLICAdvPL
01 · OVERVIEW

Overview

Survives a function return until thread/connection termination or explicit release. A same-name Private can hide it. This does not create shared global storage across users or servers. Historical training section 5.5 contains a Public example accidentally written with Private; this page uses the correct declaration. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

PUBLIC xVariavel := xValor
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed607()
    // Isolated session only; do not store secrets in Public state.
    Public _nEd607 := 10
    ConOut(_nEd607)
    Release _nEd607
Return Nil
Expected result

Prints 10 and releases the exercise-specific name. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Scope is not access control. Avoid framework names and implicit state; check reentrancy in isolated tests.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. PUBLIC. Página remissiva TDN. Accessed on 2026-10-27.
  2. TOTVS. ADVPL Fundamental V12. Seções 5.4–5.5; referência histórica consultada. 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