Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

STATIC

Static nCounter := 0

Retains state between calls in its declared scope.

STATICAdvPL
01 · OVERVIEW

Overview

The manual describes function-local Static visibility with values retained after return; declarations outside functions have source-file scope. This establishes neither database persistence nor sharing among all users. The counter demonstrates retention between helper calls; its starting value depends on existing execution state. TDN’s STATIC page is a cross-reference; the scope explanation comes from the historical manual. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

Static nCounter := 0
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed674()
    // Successive calls use the helper’s retained static state.
    ConOut(Ed674Count())
    ConOut(Ed674Count())
Return Nil

Static Function Ed674Count()
    Static nCounter := 0
    nCounter++
Return nCounter
Expected result

With initial zero state, displays 1 and 2. Later runs may start elsewhere. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Avoid caching credentials/company context in static state without lifetime and invalidation policy.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. AdvPL — O Manual. Referência histórica, p. 50. Contrato atual não homologado. Accessed on 2026-10-28.
  2. TOTVS. STATIC. Página remissiva. Accessed on 2026-10-28.
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