Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Work areas, aliases and table selection

Preserves caller context when accessing an existing alias.

Work areas, aliases and table selectionAdvPL
01 · OVERVIEW

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.)

03 · PRACTICAL EXAMPLE

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

Reads 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.

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

Related content

REFERENCES
  1. TOTVS. FwGetArea: Alias, IndexOrd, Recno. Accessed on 2026-10-28.
  2. TOTVS. DBSelectArea. Accessed on 2026-10-28.
  3. TOTVS. IndexKey. Accessed on 2026-10-28.
  4. 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
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha