Sometimes we need to perform a task on a particular application server. Most common examples of that are collecting statistics or running SQL Trace, where the data is collected only for one application server and saved locally. I had to extract the statistics data once and do that from all servers. As I could not find any function modules that would help me, I have decided to let the standard report run on each server and grab the output data. There are two ways of doing that. One is to schedule background jobs on each server. You may have noticed that in the job parameters screen of SM36 you can select an application server, where the job will be running. But in my case I would then have to implement job status checking functionality and then read the spool. Another way, which is simpler, is to create an RFC-capable function module that is going to do the job for one server, and then call it for all servers in a loop. This assumes that for each application server, you have an RFC destination, which was so in my case.
The list of available servers can be requested with the function TH_SERVER_LIST, and in my case, to get a name of the RFC destinations, I followed a simple naming convention used on our systems. It can be something like HOSTNAME_SYSID_SYSNUMBER, but surely, it can be different for you.