GetArea()Takes no arguments and returns an array containing Alias(), IndexOrd() and Recno().
AdvPL GuideaArea := GetArea() // ... processing ... RestArea(aArea)Preserve the alias, order and record before navigating tables, then return the same work context to the caller.
An AdvPL routine that selects aliases, changes orders or moves records can alter the environment expected by its caller. GetArea() captures the active alias, selected order and current record; RestArea() restores that set. When a known alias is also manipulated, preserve both the general area and that specific area. Restore the manipulated alias first and the general area last, because the last restored area remains active. Current examples also present FWGetArea() and FWRestArea() as Framework alternatives; confirm availability in the target LIB and consistently use the pair adopted by the project.
aArea := GetArea() // ... processing ... RestArea(aArea)GetArea()Takes no arguments and returns an array containing Alias(), IndexOrd() and Recno().
Alias->(GetArea())Captures a specific work area without permanently making it the routine active area.
RestArea(aArea)Receives the array returned by GetArea() and restores alias, order and record. The last restore determines the active area.
GetArea() returns an array containing the current alias, order and record number. RestArea() uses it to rebuild the saved environment.
#Include "TOTVS.ch"
User Function ExCustomerLookup()
Local aPreviousArea := GetArea()
Local cCustomerName := ""
DbSelectArea("SA1")
SA1->(DbSetOrder(1))
If SA1->(DbSeek(xFilial("SA1") + "000001"))
cCustomerName := SA1->A1_NOME
EndIf
RestArea(aPreviousArea)
Return cCustomerNameThe lookup uses SA1 without leaving its context active for the caller.
#Include "TOTVS.ch"
User Function ExProductCheck()
Local aPreviousArea := GetArea()
Local aSB1Area := SB1->(GetArea())
Local lFound := .F.
DbSelectArea("SB1")
SB1->(DbSetOrder(1))
lFound := SB1->(DbSeek(xFilial("SB1") + "000001"))
SB1->(RestArea(aSB1Area))
RestArea(aPreviousArea)
Return lFoundSB1 and the caller general environment are both restored.
#Include "TOTVS.ch"
User Function ExFrameworkArea()
Local aPreviousArea := FWGetArea()
Local aSC5Area := SC5->(FWGetArea())
DbSelectArea("SC5")
SC5->(DbSetOrder(1))
SC5->(DbGoTop())
FWRestArea(aSC5Area)
FWRestArea(aPreviousArea)
ReturnThe same pattern is used with Framework functions available in the supported LIB.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use