DBSkip and record navigation
Traverses a bounded sequence with movement and end checks.
Overview
A loop needs a start, end condition and movement. DBGoTop starts at the first logical position; DBSkip follows order and filter, and EOF must be checked before field access. The example visits at most three visible records on owned EDTRB and only counts without exposing data. Filters and deleted-record settings affect the count; it is not the table total. The alias stays at the reached position, possibly EOF. (TOTVS, n.d., refs. 1–2)
Commented example
#Include "Protheus.ch"
User Function Ed341()
Local nCount := 0
If Select("EDTRB") > 0
EDTRB->(DBGoTop())
While !EDTRB->(Eof()) .And. nCount < 3
nCount++
EDTRB->(DBSkip(1))
EndDo
ConOut(cValToChar(nCount))
EndIf
Return NilCount from zero to three, depending on visible records. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Keep movement inside the loop. Ensure a reading context without pending changes; restore area and position when the caller requires it.
- 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.