Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Safe temporary-table creation and disposal

Defines structure, lifecycle and cleanup ownership.

Safe temporary-table creation and disposalAdvPL
01 · OVERVIEW

Overview

FWTemporaryTable defines fields, creates the table and removes it through its owning object. Documentation limits visibility to the creating thread and ties features to LIB/DBAccess versions. Delete also closes the table alias rather than deleting one record. The example creates an empty temporary table and removes it on the normal path without changing business tables. A real flow must also clean up on errors and early exits; this is not a complete exception manager. (TOTVS, 2022, ref. 1)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function Ed318()
    Local oTemporary := FWTemporaryTable():New()
    Local cAlias
    // Fictional schema without business data.
    oTemporary:SetFields({{"ED_COD", "C", 10, 0}})
    oTemporary:Create()
    cAlias := oTemporary:GetAlias()
    ConOut(cValToChar((cAlias)->(LastRec())))
    oTemporary:Delete()
Return Nil
Expected result

Initially empty temporary table, expected LastRec zero; removal requested at the end. ED_COD is the fixed teaching-schema identifier. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not share the alias across threads or use another process’s physical name. Validate creation/cleanup failures and the Delete return supported by the release.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FWTemporaryTable. TDN, revisão de 10 maio 2022. Accessed on 2026-10-26.
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