Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

RecLock

RecLock(cAlias,lAdd,[l1],[lSoft],[lInJob]) -> lRet

Attempts to lock a record for insertion or update.

RecLockAdvPL
01 · OVERVIEW

Overview

RecLock(cAlias,.T.) starts an in-memory insertion; repositioning, DBCommit, MSUnlock or Recno may send the record. With .F., it attempts to lock the positioned record for update. The alias must not be a query or read-only. Always check the return before field assignments and pair with MSUnlock after setting data. Atilio does not check RecLock after SoftLock; the adaptation checks it without changing fields or treating SoftLock as a final-lock guarantee. MSUnlock does not replace external transaction commit/rollback control. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

RecLock(cAlias,lAdd,[l1],[lSoft],[lInJob]) -> lRet

Parameters

cAlias
CharacterRequired

Writable nonquery alias.

lAdd
LogicalRequired

.T. insertion; .F. update.

l1
LogicalOptional

Unused; default .F.

lSoft
LogicalOptional

Prompts for retry; default .F.

lInJob
LogicalOptional

Indicates job execution; default .F.

Return value

Logical: .T. lock obtained; .F. failure.

03 · PRACTICAL EXAMPLE

Commented example

// Update fragment: writable SB1, correct record and no pending edits.
// Run only in authorized routine context; this sample changes no fields.
If Select("SB1") > 0
    If !SB1->(Eof())
        If RecLock("SB1",.F.)
            // Only here would assignments already validated by the routine belong.
            SB1->(MSUnlock())
        Else
            // Never assign fields after failure to obtain the lock.
            ConOut("Lock not obtained")
        EndIf
    EndIf
EndIf
Expected result

Shows lock success/failure and release in normal flow, without insertion or master-data modification. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Select/EOF do not prove writability, key identity or authorization. An implementation with assignments/errors must ensure release and transaction handling on failure according to the owning routine; do not use as an ad hoc master-data update. The legacy entry had no recorded creation date. The displayed date identifies creation of this editorial-model version, without reconstructing the old page date.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. RecLock. Accessed on 2026-10-28.
  2. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_365_Funcoes_MsUnlock_RecLock_e_SoftLock.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