Opening tables
Distinguishes files, aliases, workareas and RDDs.
Overview
Opening a table binds a data source to a workarea identified by an alias. The alias differs from the physical filename; the RDD determines access behavior. DBUseArea can open a new area and specify driver, source, alias, sharing and read-only modes. A first argument of .F. or Nil may close the current area table; use .T. and a unique alias for an independent opening. File paths resolve on the server, not the SmartClient computer. The Framework index named Abertura de Tabelas lists OpenSm0/OpenSM0Excl rather than the generic DBUseArea contract. (Refs. 1–2)
Commented example
#Include "Protheus.ch"
User Function EdAbre(cFile)
Local aArea := GetArea()
Local cAlias := GetNextAlias()
// Receive an authorized path to a test DBF on the server.
If ValType(cFile) <> "C"
Return .F.
EndIf
If Empty(cFile)
Return .F.
EndIf
DBUseArea(.T., "DBFCDX", cFile, cAlias, .T., .T.)
// Close only the workarea owned by this function.
If Select(cAlias) > 0
(cAlias)->(DbCloseArea())
EndIf
RestArea(aArea)
Return .T.Demonstrates shared, read-only opening followed by owned-area closing on the normal path. File, driver and permission exceptions are not handled; wrapper .T. is not error diagnostics. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not reopen or close caller-owned aliases. Shared access may still fail when another process holds exclusive access. Production code must guarantee cleanup and restoration on error paths 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.