Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

RpcSetEnv

RpcSetEnv([cRpcEmp],[cRpcFil],[cEnvUser],[cEnvPass],[cEnvMod],[cFunName],[aTables],[lShowFinal],[lAbend],[lOpenSX],[lConnect]) -> lRet

Opens an automatic environment with company, branch and identity.

RpcSetEnvAdvPL
01 · OVERVIEW

Overview

Returns .T. on successful preparation and .F. on failure, without replacing exception handling. TDN prohibits reopening/closing menu-owned environments and warns about Schedule and REST with PrepareIn. Since 12.1.2510, framework-prepared REST/SOAP may raise an exception. cEnvPass supports an authentication token only from LIB 20251117 under the cited contract, not an arbitrary external token. The GitHub sample embeds a credential and does not close the environment in that subset; those patterns were not carried over. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

RpcSetEnv([cRpcEmp],[cRpcFil],[cEnvUser],[cEnvPass],[cEnvMod],[cFunName],[aTables],[lShowFinal],[lAbend],[lOpenSX],[lConnect]) -> lRet

Parameters

cRpcEmp
CharacterOptional

Company code.

cRpcFil
CharacterOptional

Branch code.

cEnvUser
CharacterOptional

Authorized user provided outside source.

cEnvPass
CharacterOptional

Password or token only under the supported LIB contract; never log.

cEnvMod
CharacterOptional

Module; documented default FAT.

cFunName
CharacterOptional

Routine/audit identifier; default RPC.

aTables
ArrayOptional

Aliases to open; default {}.

lShowFinal
LogicalOptional

Controls lMsFinalAuto; default .F.

lAbend
LogicalOptional

License-failure message; default .T.

lOpenSX
LogicalOptional

SX opening/first branch when absent; default .T.

lConnect
LogicalOptional

Database connection; default .T.

Return value

Opening Boolean; exceptions remain possible.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed637()
    // Uninvoked block; context and secret belong to the authorized caller.
    Local bOpen := {|cCompany,cBranch,cUser,cSecret,cModule| ;
        RpcSetEnv(cCompany,cBranch,cUser,cSecret,cModule)}
    ConOut(ValType(bOpen))
Return Nil
Expected result

Creates block B. No authentication, environment opening or secret logging occurs. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Only close an environment your routine opened and owns, using RpcClearEnv. Test licensing, permissions and failure paths.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. RpcSetEnv. TDN. Accessed on 2026-10-27.
  2. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_426_Funcao_RPCSetEnv.prw. Arquivo completo consultado; adaptação editorial. 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