DBSetOrder and DBSeek for indexed lookups
Aligns active order and key before seeking.
Overview
A DBSeek key must match the selected order expression. DBSetOrder selects a position among open orders, not a universal index number. Zero uses physical order; omitted or negative values leave the order unchanged according to the page. Changing order does not reposition the record. This fragment requires valid nOrder and cKey built for owned EDTRB, including branch when part of the expression. DBSeek with false soft seek distinguishes exact match from absence; do not read fields without checking its return. (TOTVS, n.d., refs. 1–2)
Commented example
// Fragment: nOrder and cKey validated under the caller contract.
If Select("EDTRB") > 0
EDTRB->(DBSetOrder(nOrder))
If EDTRB->(DBSeek(cKey, .F.))
ConOut("Key found")
Else
ConOut("Key absent")
EndIf
EndIfKey presence or absence message; no explicit record update. Alias order and position change. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not confuse logical return with valid position after a failed seek. Preserve caller context; navigation can flush pending changes.
- 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.