cAliasWritable nonquery alias.
AdvPL GuideRecLock(cAlias,lAdd,[l1],[lSoft],[lInJob]) -> lRetAttempts to lock a record for insertion or update.
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.)
RecLock(cAlias,lAdd,[l1],[lSoft],[lInJob]) -> lRetcAliasWritable nonquery alias.
lAdd.T. insertion; .F. update.
l1Unused; default .F.
lSoftPrompts for retry; default .F.
lInJobIndicates job execution; default .F.
Logical: .T. lock obtained; .F. failure.
// 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
EndIfShows 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.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.