Safe lookups with DbSeek, Found and SoftSeek
Distinguishes a found record from approximate positioning.
Overview
DbSeek requires an active index compatible with the key. A single numeric-field index uses a numeric key; other cases must follow the index expression and field lengths. True SoftSeek can position at a greater key without finding the requested value: false does not authorize treating that record as a match. Found retrieves the search result; inspect it immediately in the same context. The DBSeek page gives conflicting lLast guidance; the example omits it and disables SoftSeek. The fragment selects neither index nor key format: both are explicit caller preconditions. (TOTVS, n.d., refs. 1–2)
Return value
No single return value: this is a composite workflow.
Commented example
// Fragment: current alias open, active index and compatible cKey.
lFound := DbSeek(cKey, .F.)
If lFound .And. Found()
// Read matched record fields only here.
ConOut("Key found")
Else
ConOut("Key not found")
EndIfOutcome depends on key and data. The example repositions the alias without writing or restoring its prior position. Declare key and logical variable in the caller. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Validate alias, index, filter and branch before lookup. Save/restore context when required and do not interleave another search before Found.
- 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.