STATIC
Static nCounter := 0Retains state between calls in its declared scope.
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.)
Syntax
Static nCounter := 0Commented 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 nCounterWith 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.
- 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.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.