Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Record insertion, editing, logical deletion and persistence

RecLock(cAlias,lAdd) → fields → MsUnlock(); DBDelete()

Distinguishes locking, field changes and logical deletion.

Record insertion, editing, logical deletion and persistenceAdvPL
01 · OVERVIEW

Overview

RecLock(alias,.T.) starts insertion and .F. attempts to lock the positioned record for editing; check its result before writes. MsUnlock ends the lock but alone is not a multi-table business transaction. DBDelete marks logical deletion rather than physically removing data. This example uses an owned temporary table without production records. The referenced community code contains messages inside a transaction and unchecked RecLock calls; those parts are not reproduced. (Sources: refs. 1–3.)

02 · SYNTAX

Syntax

RecLock(cAlias,lAdd) → fields → MsUnlock(); DBDelete()
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed485()
    Local oTmp := FWTemporaryTable():New(GetNextAlias(),{{"ED_TEXT","C",20,0}})
    Local cAlias
    // Test temporary table only.
    oTmp:Create()
    cAlias := oTmp:GetAlias()
    If RecLock(cAlias,.T.)
        (cAlias)->ED_TEXT := "ED01"
        (cAlias)->(MsUnlock())
    EndIf
    (cAlias)->(DbGoTop())
    If !(cAlias)->(Eof())
        If RecLock(cAlias,.F.)
            (cAlias)->ED_TEXT := "ED02"
            (cAlias)->(DbDelete())
            (cAlias)->(MsUnlock())
        EndIf
    EndIf
    oTmp:Delete()
    FreeObj(oTmp)
Return Nil
Expected result

Demonstrates insertion, editing and deletion marking in a temporary table, then removes the owned table. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Prefer business routines and MVC for real records. Provide failure handling, cleanup and concurrency control.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. RecLock. TDN. Accessed on 2026-10-27.
  2. TOTVS. FWTemporaryTable. TDN. Accessed on 2026-10-27.
  3. Daniel Atilio. zGravacao.prw; commit 7d275a7. Accessed on 2026-10-27.
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