Aggressive pipeline management is indeed a good practice. Services should drop vars as soon as possible when finished with them. Some people like to use clearPipeline a lot but I much prefer dropping vars explicitly as soon as possible to keep the pipeline minimized.
You’ve described the behavior of variable handling perfectly. Documents are copy by reference, primitive var types are copy by value.
-
It is not “A’s pipeline”. It is “the pipeline” that all services within the thread will use. All vars in a pipeline are visible to all services (there are exceptions: transformers and services called with a scope do not have full visibility).
-
Service B just replaced “doc” for everyone within the thread.
There is no “copied back”. There is only the pipeline.
Calls to other services do not have a stack, like you’re used to in C/C++, C#, Java, etc. It “appears” that services accept “parameters” and have explicit return variables, but they do not. The input and output declarations are design time helpers only. They are used to identify what variables a service expects to be in the pipeline at run-time and which variables will be added to the pipeline. But at run-time, there is no enforcement of this and parameters don’t need to be declared on the input/output tab for a service to function correctly.
You’ve discovered one of the fundamental “gotchas” of IS. When everything is a global variable, it can be challenging to keep services from stomping on each other. But this isn’t really as big of a deal as it seems.
As you get into designing services for your integrations you’ll find that global and local var names (conceptually) naturally emerge. Use descriptive names (e.g. purchaseOrder) rather than generic names (e.g. doc). As you get familiar with the built-in services you’ll get a good feel for var names to avoid as globals. For example, “doc” won’t last very long in any sequence of calls. Using doc locally for a few steps is okay, but not for long-lived var over multiple services. It will eventually get clobbered by a call to a built-in service of some sort.
HTH
#Integration-Server-and-ESB#webMethods#Flow-and-Java-services