User Function
User Function <Nome>()Declares a public function that can be called by the environment, menus, entry points or other AdvPL routines.
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.
Syntax
User Function <Nome>()Simple public routine
#Include "TOTVS.ch"
User Function CursoADVPL()
Local cMensagem := "Primeira rotina AdvPL"
MsgInfo(cMensagem, "Treinamento")
ReturnThe U_CursoADVPL function can be called by the environment or another source according to the calling convention used.
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")
ReturnThe User Function remains the entry point and the helper rule stays encapsulated in the same source.
- 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.
- 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.

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