Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

GETAREA()

GetArea() -> aArea

Captures alias, order and record for context restoration.

GETAREA()AdvPL
01 · OVERVIEW

Overview

GetArea returns an array containing Alias(), IndexOrd() and Recno(). Evaluate it inside another alias to capture that table. RestArea restores context; the last restored area becomes active. It does not save filters, relationships, all open tables or company context. FwGetArea offers equivalent LIB functionality and is recommended by TOTVS. This adaptation uses the legacy pair to make GetArea/RestArea correspondence explicit and checks SB1 before access. (Sources: refs. 1–4.)

02 · SYNTAX

Syntax

GetArea() -> aArea

Return value

Array: [1] alias; [2] order; [3] Recno.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed745()
    Local aOriginal := GetArea()
    Local aProduct := {}
    If Select("SB1") > 0
        // Capture the inspected table while retaining original context.
        aProduct := SB1->(GetArea())
        ConOut(SB1->(IndexKey()))
        RestArea(aProduct)
    EndIf
    // The final restore returns the active area to the caller.
    RestArea(aOriginal)
Return Nil
Expected result

Reads index metadata and restores areas in normal flow. Does not open, close or traverse tables. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not restore a table your routine closed or treat the snapshot as transaction protection. Implement cleanup for error exits too.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. GETAREA. Accessed on 2026-10-28.
  2. TOTVS. RESTAREA. Accessed on 2026-10-28.
  3. TOTVS. FwGetArea: Alias, IndexOrd, Recno. 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

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