@Vitaliy Serdtsev  Thank you. I still need a bit more clarification.
• In which namespace is ^IRIS.TempRSet located?
• Am I correct in assuming that this mechanism relies on Process Private Globals (similar to Robert’s option)? If not, how can I view the global values in the SMP?
• Does each “rs” value get stored directly in ^IRIS.TempRSet, or does each "rs" data have its own node within ^IRIS.TempRSet? If it saved in separate node, how a name for such a node can be determine?
• Are the stored data/nodes removed automatically, or do they require a manual KILL operation?

@Robert Cemper While all steps are verified, I am failing to use a variable table name in  &SQL(DROP..

Set tStamp = $REPLACE($ZTIME($PIECE($HOROLOG,",",2),1),":","") // in hhmmss format
Set tTable = "%ZZ.resultset"_ tStamp

// Note tTable works for "CREATE GLOBAL TEMPORARY TABLE "_tTable_" as " as well as in SELECT * FROM "_tTable

//Failure
&SQL(DROP TABLE tTable)

Can variable be used in such content? Am I missing something? Thank you

@Robert Cemper 

What am I missing? Thank you

=======

ClassMethod SelectNS

{

ZN "HSACCESS"
&SQL(DROP TABLE %ZZ.resultset
Set sql=2,
sql(1)="CREATE GLOBAL TEMPORARY TABLE %ZZ.resultset as ",
sql(2) ="SELECT * FROM Ens.MessageHeader"
Set statement=##class(%SQL.Statement).%New()
Set result=statement.%ExecDirect(.statement,.sql)
Set = result.%SQLCODE // a = 0 
ZN "HSCUSTOM"
// Attempt to verify via MP>"HSACCESS">SQL:
// SELECT * FROM Ens.MessageHeader  > Row count: 8..
// SELECT * FROM %ZZ.resultset  > Row count: 0 ...
// Pay attention that there is NO error "Table '%ZZ.RESULTSET' not found"
// Attempt to verify via MP>"HCUSTOM">SQL:
// SELECT * FROM %ZZ.resultset  > Row count: 0 ...
// Pay attention that there is NO error "Table '%ZZ.RESULTSET' not found"

}

@Robert Cemper I understand about extended global reference - it is not an issue. 

I have issue to execute "..CREATE GLOBAL TEMPORARY TABLE %ZZ.resultset.." related steps from QobjectScript. 

Creating a temp (%ZZ..)  table, following by it's population and finally dropping it (as you described in your post) must be done programmatically from ObjectScript. 

Thank you for guidance.

@Robert Cemper 

Thank you—this looks promising. However, when I attempt to reproduce it in Caché ObjectScript, I’m running into syntax errors. Could you please provide a complete ObjectScript example that implements all the steps described above? Thank you.

Thank you @Evgeny Shvarov. Transferring result from namespace A to namespace B is not a single action to handle. It is an application-wide utility to allow query execution in one namespace and handling a result in another for new and ALREADY exist queries. So, options 2,3,4 above can not be implemented.

But option 1 seems promising if it could be done programmatically. Please, provide code example to TEMPORARILY "map the data for namespace B  via global mappings.." and kill such mapping upon getting a result. Thank you.

Per ISC documentation (don't remember correlated section), query ResultSet (%SQL.StatementResult) , executed in one namespace, can not be directly viewed/parsed in a different namespace. Upon ZN to the original namespace, ResultSet is empty.

I am trying to resolve it, by the following steps:

  1. ZN form original namespace (ONS) to execution namespace (ENS)
  2. Execute query in ENS and get ResultSet 
  3. While in ENS, convert ResultSet to JSON
  4. ZN to ONS.
  5. JSON is still valid and not empty
  6. While in the original ONS, convert JSON to ResultSet to use it.

 Steps 1 - 5 are done and tested. 

I am looking for a code (step 6) to convert JSON to ResultSet.

Did I select a wrong approach?

Thank you

Sorry - I didn't find a code correlated to my  question. 

I am looking for code EXAMPLE to convert JSON string into ResultSet (%SQL.StatementResult).

Thank you