RpcSetEnv and environment preparation
Defines who opens, uses and closes an automatic environment.
Overview
First identify the caller: menu, Schedule and REST PrepareIn can already provide a prepared environment. Preserve that context and its policies. For an isolated job that needs one, obtain credentials through a protected channel, call RpcSetEnv, check its return and process only on success. Track ownership and close only your environment with RpcClearEnv, including error cleanup. Select("SX2") alone proves neither identity, branch nor permission. This example only demonstrates a fictional ownership flag without opening/closing connections. (Sources: refs. 1–2.)
Commented example
#Include "Protheus.ch"
User Function Ed638()
// Teaching flag; real ownership comes from actual opening.
Local lOwnedEnvironment := .F.
If lOwnedEnvironment
// Actual cleanup must cover failure paths too.
ConOut("OWNED_CLEANUP")
EndIf
Return NilSkips cleanup because it opened no environment. This is a decision model, not a ready job wrapper. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not switch companies or reauthenticate framework-prepared REST/SOAP. Check release and LIB.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

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