Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

DEFAULT

DEFAULT xParametro := xValor

Provides a default for an omitted parameter.

DEFAULTAdvPL
01 · OVERVIEW

Overview

DEFAULT is the traditional way to supply a value when a parameter is Nil; zero, false and empty text are not absence. The example applies a default then checks type because DEFAULT does not validate supplied arguments. Current documentation presents FWADVPLDEFAULT for AdvPL parameters and distinguishes TLPP FWDEFAULT/FWNULLDEFAULT. Those forms require updated Protheus.ch, a predeclared parameter and individual use; do not assume old-include availability or use them to create Private variables. (TOTVS, n.d., refs. 1–2)

02 · SYNTAX

Syntax

DEFAULT xParametro := xValor

Parameters

xParametro
AnyRequired

Parameter already declared in the function.

xValor
AnyRequired

Default value compatible with the contract.

Return value

Conditional assignment command, not a function with its own return.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function Ed346(nValue)
    // Supplied zero remains zero; an omitted argument receives 10.
    Default nValue := 10
    If ValType(nValue) <> "N"
        Return Nil
    EndIf
Return nValue * 2
Expected result

U_Ed346() returns 20; U_Ed346(0) returns 0; text returns Nil after validation. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Distinguish missing from invalid values. Choose current macros according to language, types and the actual include.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Default de Parâmetros de Função. TDN. Accessed on 2026-10-26.
  2. TOTVS. Defaults - ADVPL e TLPP. TDN. 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