Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONUnder review

Opening tables

Distinguishes files, aliases, workareas and RDDs.

Opening tablesAdvPL
01 · OVERVIEW

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)

03 · PRACTICAL EXAMPLE

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.
Expected result

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.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. DBUseArea. TOTVSTEC/TDN. Accessed on 2026-10-24.
  2. TOTVS. Abertura de Tabelas. Índice Frameworksp. Accessed on 2026-10-24.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha