Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Indexes, orders and lookups in Protheus tables

Checks the order expression before building a lookup key.

Indexes, orders and lookups in Protheus tablesAdvPL
01 · OVERVIEW

Overview

DBSetOrder selects an open area’s logical order and may fail for nonexistent orders. IndexKey returns its expression as text without creating/rebuilding indexes. DBSeek requires a compatible order, key type and composition; check its Boolean result before reading fields. With lSoftSeek true, approximate positioning may occur even when the return is false: position does not prove a match. This sample only inspects SB1’s current order rather than assuming order number, width or code. SQL ORDER BY and physical index selection are separate issues. (Sources: refs. 1–4.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed738()
    Local cExpression := ""
    // Inspect an existing alias without changing order or position.
    If Select("SB1") > 0
        cExpression := SB1->(IndexKey())
    EndIf
    ConOut(cExpression)
Return Nil
Expected result

Displays the current expression or an empty string; does not look up a product. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not trim fixed-width key components. Preserve area/order if processing changes them; do not apply the technical sample’s table-creation routine to standard tables.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. IndexKey. Accessed on 2026-10-28.
  2. TOTVS. DBSetOrder. Accessed on 2026-10-28.
  3. TOTVS. DBSeek. Accessed on 2026-10-28.
  4. TOTVS. Desenvolvendo queries no Protheus. Accessed on 2026-10-28.
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