Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

PREPARE ENVIRONMENT

PREPARE ENVIRONMENT EMPRESA cEmpresa FILIAL cFilial MODULO cModulo

Defines context for automatic execution without an existing environment.

PREPARE ENVIRONMENTAdvPL
01 · OVERVIEW

Overview

The historical reference shows company, branch and module in the command. Current RpcSetEnv automatic-environment documentation requires context awareness: menu routines already have an environment; REST/SOAP with PrepareIn and schedules may too. Do not reopen, switch or close that context. Since 12.1.2510, RpcSetEnv can raise an exception in services whose environment is already open. This example records commented historical syntax only, without opening an environment or reproducing illustrative credentials from sources. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

PREPARE ENVIRONMENT EMPRESA cEmpresa FILIAL cFilial MODULO cModulo

Parameters

cEmpresa
CharacterRequired

Company authorized for the process.

cFilial
CharacterRequired

Branch matching the company.

cModulo
CharacterRequired

Automatic-process module.

Return value

Command: no function return in this syntax. RpcSetEnv has its own logical-return contract.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed596()
    // Syntax only: opening, authentication and cleanup require the caller contract.
    // PREPARE ENVIRONMENT EMPRESA cCompany FILIAL cBranch MODULO "FAT"
    ConOut("PREPARE ENVIRONMENT")
Return Nil
Expected result

Prints the command name; does not change company, branch or user. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • For an owned job, define an authorized identity, check opening failure and clean up only the environment the routine opened. Resolve credentials outside source code and avoid administrator/blank-password defaults. Check includes and release before activating the command.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. Waterloo Ferreira da Silva. AdvPL — O Manual, versão 1.0, p. 405. Referência histórica. Accessed on 2026-10-27.
  2. TOTVS. RpcSetEnv. TDN. Accessed on 2026-10-27.
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