Indexes, orders and lookups in Protheus tables
Checks the order expression before building a lookup key.
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.)
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 NilDisplays 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.
- 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.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.