Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Recno queries and DbGoTo positioning

Separates the SQL cursor from the positioned real table.

Recno queries and DbGoTo positioningAdvPL
01 · OVERVIEW

Overview

A recno query selects the real table R_E_C_N_O_ under an alias, converts the numeric field when needed, and scans a read cursor. Each recno can position the real table with DbGoTo. The query neither locks nor validates a later update: recheck existence, branch, deletion and business rules before writing. This example uses an already-open caller-owned cursor with numeric A1RECNO and an open SA1, without writes. Preserve SA1 position separately when repositioning it. (Sources: refs. 1–2.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed609()
    // Uninvoked block; cQuery must contain numeric A1RECNO.
    Local bPosition := {|cQuery| SA1->(DbGoTo((cQuery)->A1RECNO))}
    ConOut(ValType(bPosition))
Return Nil
Expected result

Builds the positioning step without opening a query or changing a table. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • During scanning, Eof and DbSkip belong to the cursor, not the positioned table; use a dynamic alias and close only your cursor.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Desenvolvendo queries no Protheus. Accessed on 2026-10-27.
  2. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_535_Classe_WsRestFul.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