Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

RecLock and MsUnlock in introductory maintenance

Checks a lock before changing a record.

RecLock and MsUnlock in introductory maintenanceAdvPL
01 · OVERVIEW

Overview

RecLock with .F. tries to lock the current record; .T. starts an insert. Assign fields only after .T., then finish with MsUnlock in the same alias. SQL cursors and read-only aliases cannot use this flow. Within an explicit transaction MsUnlock is still required, but locking can persist until transaction end. This example is only a no-assignment update cycle on an open positioned sandbox ZZ1, not a complete registration routine. Prefer supported automatic routines/models for standard tables. (Sources: refs. 1–3.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed613()
    // Run only on an open, positioned sandbox ZZ1.
    If Select("ZZ1") > 0
        If !ZZ1->(Eof())
            If RecLock("ZZ1",.F.)
                // Validated assignments would be made here.
                ZZ1->(MsUnlock())
            EndIf
        EndIf
    EndIf
Return Nil
Expected result

When preconditions hold, attempts to lock and finish without field changes. No writes on lock failure. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • SoftLock is not proof that RecLock succeeded. Plan errors/restoration without unlocking another owner’s resources.
  • 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-27.
  2. TOTVS. MsUnlock e transações. Accessed on 2026-10-27.
  3. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_365_Funcoes_MsUnlock_RecLock_e_SoftLock.prw. Arquivo completo consultado; adaptação editorial. 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