Work areas, aliases and table selection
Preserves caller context when accessing an existing alias.
Overview
A work area holds an open-table context; its alias identifies it. DBSelectArea changes the active area; ALIAS->(...) operates on another area without leaving that selection as caller context. FwGetArea saves only Alias, IndexOrd and Recno. Before repositioning another table, capture that table too and restore the original area last. This does not back up filters, relations, transactions or company context. The adaptation checks that SB1 is open before using Atilio’s two-area preservation pattern. (Sources: refs. 1–4.)
Commented example
#Include "Protheus.ch"
User Function Ed735()
Local aOriginal := FWGetArea()
Local aTarget := {}
// Caller owns the table: do not open or close it here.
If Select("SB1") > 0
aTarget := SB1->(FWGetArea())
ConOut(SB1->(IndexKey()))
// Restore target table first and caller context last.
FWRestArea(aTarget)
EndIf
FWRestArea(aOriginal)
Return NilReads the current index expression, or skips SB1 if unopened; does not traverse records. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- The flow assumes calls complete without errors. Real processing needs cleanup on error exits too; do not close caller aliases with DbCloseAll.
- 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.