Usina BRAdvPL Guide
Sign in
← All topics
FOUNDATIONPublished

Protheus include files

#Include "<arquivo>.ch"

Understand the role of .ch files and choose the appropriate include for each context.

CompilationConfigurationSyntax
01 · OVERVIEW

Overview

Include files gather definitions, constants and commands that the compiler must know when processing AdvPL source code. The #Include directive incorporates these definitions during compilation; it does not load an executable library at runtime. The include folder must match the environment and be correctly configured in the compilation tool.

02 · SYNTAX

Syntax

#Include "<arquivo>.ch"
03 · PRACTICAL EXAMPLE

General base: TOTVS.ch

#Include "TOTVS.ch"

User Function ExInclude()
    Local cMensagem := "General include configured"
    MsgInfo(cMensagem)
Return
Expected result

Use TOTVS.ch as the general include in new source files. PROTHEUS.ch remains present in many examples and existing code; RWMAKE.ch should be treated as legacy.

04 · PRACTICAL EXAMPLE

MVC: FWMVCDef.ch

#Include "TOTVS.ch"
#Include "FWMVCDef.ch"

User Function ExMVC()
    Local oModel := FWLoadModel("MATA020")

    oModel:SetOperation(MODEL_OPERATION_INSERT)
Return
Expected result

FWMVCDef.ch provides definitions used by the MVC architecture, including model operation constants.

05 · PRACTICAL EXAMPLE

SQL queries: TopConn.ch

#Include "TOTVS.ch"
#Include "TopConn.ch"

User Function ExQuery()
    Local cQuery := "SELECT A1_COD FROM " + RetSqlName("SA1")

    TCQUERY (cQuery) ALIAS QRY NEW
    QRY->(DbCloseArea())
Return
Expected result

TopConn.ch is required for specific relational access commands such as TCQUERY. The official documentation recommends NEW to avoid unintentionally closing the current work area.

06 · PRACTICAL EXAMPLE

Environment preparation: TBICONN.ch

#Include "TOTVS.ch"
#Include "TBICONN.ch"

User Function ExAmbiente()
    PREPARE ENVIRONMENT EMPRESA "01" FILIAL "01" MODULO "FAT"

    ConOut("Environment prepared")

    RESET ENVIRONMENT
Return
Expected result

TBICONN.ch appears in non-interface routines that use PREPARE ENVIRONMENT and RESET ENVIRONMENT. Company, branch, module and table values depend on the process being run.

07 · PRACTICAL EXAMPLE

REST services: RestFul.ch

#Include "TOTVS.ch"
#Include "RestFul.ch"

// WSRESTFUL, WSDATA and WSMETHOD declarations
// depend on definitions provided by RestFul.ch.
Expected result

RestFul.ch is used to declare AdvPL REST services based on commands and definitions from the REST framework.

BEST PRACTICES
  • Use only the includes required by the feature used in the source code.
  • Keep the include package aligned with the Protheus release and update level.
  • According to official TOTVS guidance, prefer TOTVS.ch as the general base; it points to PROTHEUS.ch and may receive future definitions.
  • Document specific includes when their absence does not produce an intuitive compilation error.
COMMON PITFALLS
  • RWMAKE.ch is an old include and is not recommended for new development; legacy code may still use it.
  • A missing, outdated or mismatched include folder can cause unknown commands, missing identifiers or differences between environments.
  • Adding many includes indiscriminately can hide actual dependencies and make maintenance harder.
  • Not every function requires a specific include; consult the documentation for the command or feature being used.

Related content

REFERENCES
  1. TOTVS. ADV0100 — Which include to use: RWMAKE.ch, PROTHEUS.ch or TOTVS.ch. TDN.
  2. TOTVS. AdvPL commands: configuring the include folder. TDN.
  3. TOTVS. TCQUERY command and TopConn.ch. TDN.
  4. TOTVS. AdvPL using MVC manual, version 4.0.
  5. TOTVS. First REST API in AdvPL and RestFul.ch. TDN.
  6. TOTVS. AdvPL using MVC. Supplied 134-page PDF, generated June 1, 2018; related content reviewed August 2, 2026.
  7. TOTVS. Developing queries in Protheus. TDN.
  8. MICROSIGA. Programming Manual. Collaborative document, file dated July 11, 2001. Historical reference.
  9. MICROSIGA. Manual de Programação. Documento colaborativo, arquivo datado de 11 jul. 2001. Referência histórica.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR