Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

DbSelectArea

DBSelectArea(xArea)

Selects an open work area by alias or valid number.

DbSelectAreaAdvPL
01 · OVERVIEW

Overview

DBSelectArea changes the active work area; unqualified operations then use that area. It neither opens a table nor locates a key. TDN gives conflicting guidance for invalid arguments: it describes errors for numbers at or below zero and deactivation in other cases. This revision removes advice to use zero to find a free area, which this source does not support. The sample only selects an already open alias and restores original context. (Sources: refs. 1–3.)

02 · SYNTAX

Syntax

DBSelectArea(xArea)

Parameters

xArea
Character or numericRequired

Open alias or valid area number.

Return value

The consulted entry does not specify a return contract; the sample does not use it.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed746()
    Local aOriginal := FWGetArea()
    // Check the alias is open before making it active.
    If Select("SB1") > 0
        DBSelectArea("SB1")
        ConOut(Alias())
    EndIf
    // This sample owns no aliases: do not close tables.
    FWRestArea(aOriginal)
Return Nil
Expected result

With SB1 open, displays SB1 and restores the original area; otherwise does not select SB1. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not treat area-selection return as record-lookup proof. Consider an aliased expression for a single read. Error-path restoration needs additional handling in the real routine. The legacy entry had no recorded creation date. The displayed date identifies creation of this editorial-model version, without reconstructing the old page date.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. DBSelectArea. Accessed on 2026-10-28.
  2. TOTVS. FwGetArea: Alias, IndexOrd, Recno. Accessed on 2026-10-28.
  3. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_220_Funcoes_FWGetArea_FWRestArea_GetArea_e_RestArea.prw. Arquivo completo analisado; adaptação editorial. Accessed on 2026-10-28.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR

Was this content helpful?

👍 Like 0👎 Dislike 0

Sign in to rate this article.

0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha