Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

EXISTCHAV()

ExistChav( alias, expressao, [indice], [help] ) --> lRet

Validates key uniqueness.

EXISTCHAV()AdvPL
01 · OVERVIEW

Overview

ExistChav approves an absent key and rejects a duplicate. Supply the expression without branch as documented; do not automatically reuse a DBSeek key. Omitted index uses the first index. Rejection can display help, so this is not a generic silent lookup. The GitHub source demonstrates SA1 code/store calls; this proposal uses a parameterized callback without querying real records. Prevalidation alone does not solve concurrency or transactional uniqueness. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

ExistChav( alias, expressao, [indice], [help] ) --> lRet

Parameters

alias
CharacterRequired

Validation alias.

expressao
CharacterRequired

Key without branch.

indice
NumericOptional

Order matching the expression.

help
CharacterOptional

Rejection help name.

Return value

True when its rule is satisfied; false on rejection.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed373()
    Local bValidate := {|cAlias,cKey,nOrder| ExistChav(cAlias,cKey,nOrder)}
    // Branch-free key and matching order; do not evaluate here.
Return Nil
Expected result

Block prepared without lookup; return meaning depends on each function’s rule. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Confirm release-specific validation context, order and messages. Do not confuse the two logical meanings.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. EXISTCHAV(). TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Validacao/ExistChav.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado. 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