Object script analog of RCOPY
I am trying to figure out the best ObjectScript analog to mimic, more or less, the %RCOPY functionality. What would be ObjectScript method(s) if any to copy a routine from the current namespace to another one and compile it there?
Product version: Caché 2017.1
I would recommend package mapping, unless you have a reason for the code to be different in the same routine between the namespaces? I have used package mapping for a while so it should be an option in older versions as well:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
That would make the routine from namespace A immediately available in namespace B as is. The goal is to have routines in two namespaces different until the time comes for the programmer to make them the same via an RCOPY analog. It is also a "per routine" job used for synchronizing.
It's a bit clunky, but you could use %SYSTEM.OBJ::ExportToStream in the source namespace followed by %SYSTEM.OBJ::LoadStream in the target namespace.
Thanks! Let's see if there are less "clunky" ways
Marc, a slight variation on your idea, tested whether targetRtn exists or not. Thanks again!
s currRtn=(##class(%Routine).%OpenId(rtnName))
s stream=currRtn.Read()
zn "B"
s targetRtn=(##class(%Routine).%OpenId(rtnName))
s sc=targetRtn.Write(stream)
d targetRtn.Save()
What's bad about using %RCOPY if you want it ?
.png)
I think OP needs non-interactive approach.
Robert, it does not trigger source control and yes, I'd like it non-interactive too.
Also %RCOPY preserves date modified of the original routine, and I'd rather preserve it. So far other listed approaches do not preserve it.
Probably a bit old-fashioned and maybe too simple, but this still works:
x "zl @rtn zn tns zs @rtn"
where rtn is the routine name and tns contains the name of the 'to' namespace.
Yes, that works and assigns the time of copy as the date modified. Thanks, Stephen! BTW, in my experience at least some old-fashioned commands are faster than their modern equivalents though in this case the speed is not an issue.
That approach works only for *.INT routines. Don't you use *.MAC and *.INC as well?