Safe temporary-table creation and disposal
Defines structure, lifecycle and cleanup ownership.
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)
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 NilInitially 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.
- 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.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.