Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

DbCreateIndex

DBCreateIndex( <cName>, <cExprKey>, [bExprKey], [lUnique] ) --> Nil

Creates an index for the current table or view.

DbCreateIndexAdvPL
01 · OVERVIEW

Overview

DBCreateIndex takes an index name and key expression with optional block and uniqueness. Documentation warns that an existing same-name index can be replaced and that the operation closes indexes, activates the new order and repositions records. The block should reflect the key value rather than the text containing its expression. The analyzed community file returns cIndice from its block; we do not reproduce that as an executable-key model. The fragment requires a new index and an owned RDD-compatible table. EDTRB identifies only an owned test table already open with the required schema and permissions; examples are not intended for standard tables. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

DBCreateIndex( <cName>, <cExprKey>, [bExprKey], [lUnique] ) --> Nil

Parameters

cName
CharacterRequired

New index name, different from the table in TOPCONN.

cExprKey
CharacterRequired

Text key expression.

bExprKey
Code blockOptional

Equivalent executable expression.

lUnique
LogicalOptional

Unique-index option; check RDD semantics.

Return value

Nil; not a logical success indicator.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed329()
    // ED_NEWIDX must be unused; owned EDTRB has field ED_COD.
    If Select("EDTRB") > 0
        EDTRB->(DBCreateIndex("ED_NEWIDX", "ED_COD", {|| ED_COD}, .F.))
    EndIf
Return Nil
Expected result

Proposes index creation and test-context order changes; not a neutral lookup. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check RDD, alias and pending operations. Navigation can flush updates; preserve context under the caller contract and handle errors in the complete routine.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. DbCreateIndex. TDN. Accessed on 2026-10-26.
  2. EURAI. dbCreateIndex.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado com ressalva sobre o bloco. Accessed on 2026-10-26.
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