GETAREA()
GetArea() -> aAreaCaptures alias, order and record for context restoration.
Overview
GetArea returns an array containing Alias(), IndexOrd() and Recno(). Evaluate it inside another alias to capture that table. RestArea restores context; the last restored area becomes active. It does not save filters, relationships, all open tables or company context. FwGetArea offers equivalent LIB functionality and is recommended by TOTVS. This adaptation uses the legacy pair to make GetArea/RestArea correspondence explicit and checks SB1 before access. (Sources: refs. 1–4.)
Syntax
GetArea() -> aAreaReturn value
Array: [1] alias; [2] order; [3] Recno.
Commented example
#Include "Protheus.ch"
User Function Ed745()
Local aOriginal := GetArea()
Local aProduct := {}
If Select("SB1") > 0
// Capture the inspected table while retaining original context.
aProduct := SB1->(GetArea())
ConOut(SB1->(IndexKey()))
RestArea(aProduct)
EndIf
// The final restore returns the active area to the caller.
RestArea(aOriginal)
Return NilReads index metadata and restores areas in normal flow. Does not open, close or traverse tables. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not restore a table your routine closed or treat the snapshot as transaction protection. Implement cleanup for error exits too.
- 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.