Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONPublished

User Function

User Function <Nome>()

Declares a public function that can be called by the environment, menus, entry points or other AdvPL routines.

FunctionsSource structureFoundationsRoutines
01 · OVERVIEW

Overview

User Function is the traditional way to declare an externally accessible AdvPL routine. The informed name identifies a function that may be executed from menus, direct calls, entry points or other environment mechanisms. In older training material, it appears as the first structure used to create an executable routine.

02 · SYNTAX

Syntax

User Function <Nome>()
03 · PRACTICAL EXAMPLE

Simple public routine

#Include "TOTVS.ch"

User Function CursoADVPL()
    Local cMensagem := "Primeira rotina AdvPL"

    MsgInfo(cMensagem, "Treinamento")
Return
Expected result

The U_CursoADVPL function can be called by the environment or another source according to the calling convention used.

04 · PRACTICAL EXAMPLE

User Function calling a helper function

#Include "TOTVS.ch"

User Function ExRelatorio()
    Local cTitulo := "Relatório introdutório"

    U_MostraTitulo(cTitulo)
Return

Static Function MostraTitulo(cTitulo)
    MsgInfo(cTitulo, "Título")
Return
Expected result

The User Function remains the entry point and the helper rule stays encapsulated in the same source.

BEST PRACTICES
  • Use nomes claros, curtos e estáveis para rotinas chamadas externamente.
  • Declare variáveis locais logo no início do bloco para reduzir criação implícita de Private.
  • Mantenha o retorno compatível com o contrato esperado por quem chama a função.
  • Evite misturar muitas responsabilidades em uma única User Function; extraia regras para funções auxiliares.
COMMON PITFALLS
  • Renaming a User Function used by menus, entry points or external calls breaks the reference.
  • Too many public functions make governance and maintenance harder.
  • Historical examples use RWMake.ch; for new sources, evaluate TOTVS.ch according to current environment guidance.

Related content

REFERENCES
  1. Apostila ADVPL Introd. Microsiga Campinas, 2001. Documentação oficial histórica de caráter didático e de suporte. Conteúdo histórico, resumido, revisado e adaptado para guia de referência.
Status
Published
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