API to import/export routines
This is an article on the InterSystems FAQ site.
1. Export API
a. Use $system.OBJ.Export() to specify individual routines to export. For example:
do $system.OBJ.Export("TEST1.mac,TEST2.mac","c:\temp\routines.xml",,.errors)The format to specify is routine name.extension, and the extension is mac, bas, int, inc, obj.
Errors during export are stored in errors.
See the class reference %SYSTEM.OBJ for details on $system.OBJ.Export().
b. Use $system.OBJ.Export() even when exporting with wildcards. For example:
*Before version 2008.1, use $system.OBJ.ExportPattern().
c. Use $system.OBJ.ExportUDL() for individual export rather than export in xml format. For example:
2. Import API
a. Use $system.OBJ.Load() to import all routines contained in the file. For example:
do $system.OBJ.Load("c:\temp\routines.xml",,.errors)
b. Import only some of the routines contained in the file
If you want to select and import only some of the routines included in the XML file, set the 5th argument listonly to 1 once to load the XML file with $system.OBJ.Load(), and set the 4th argument (output argument ) to select the import target from the list obtained and specify it with the 6th argument. For example:
Set file="c:\temp\routines.xml"
// First get the list of items contained in the XML
Do $system.OBJ.Load(file,,.errors,.list,1 /* listonly */)
Set item=$Order(list(""))
Kill loaditem
While item'="" {
If item["Sample" Set loaditem(item)="" { // Import only those containing Sample
Set item=$Order(list(item))
}
}
// Execute import process with created list
Do $system.OBJ.Load(file,,.errors,,,.loaditem)c. You can also use $system.OBJ.ImportDir to import multiple files under that directory. For example:
do $system.OBJ.ImportDir("c:\temp","*.cls","ck")Comments
Useful article, @Hiroshi Sato san! For source control I recommend $system.OBJ.ExportUDL() method to export in CLS, MAC, INC formats. $system.OBJ.Load() and $system.OBJ.LoadDir() methods support both XML and UDL formats
Hi, Evgeny
Thanks for your comment.
I have slightly changed the content based on your suggestion.