Michael is a
Curious Researcher
Recap 2022
Top Post:
people reached
User bio
404 bio not found
Member since Feb 17, 2022

This worked for me as well. In my case I was parsing an XML file ANSI encoded without proper header. Once the stream hit a special charachter (in my case "à") it wouldn't recognize it. I presume %XML.XPATH.Document and %XML.TextReader default to UTF-8 in this case, after converting the stream I was able to parse without issues.

set cda2Stream = ##class(%Stream.FileBinary).%New()
// Converting to UTF-8 encoding as the original stream is ANSI encoded without proper header
set convertedStream = ##class(%Stream.GlobalBinary).%New()
while 'cda2Stream.AtEnd {
// Parsing the converted stream
set XpathDoc.PrefixMappings = "s urn:hl7-org:v3"

I think XML would be the best way, especially if you want to do it programmatically. This snippet will export your table to the specified folder

ClassMethod ExportTable(table As %String, path As %String)
	set class = $replace($replace(table,"_",""),"SQLUser.","User.")
	set sqlQuery = "select $listbuild(%Id,'"_class_"') as oid from "_table
	set rset = ##class(%SQL.Statement).%ExecDirect(,sqlQuery)
	while rset.%Next() {
		set elements(rset.%Get("oid"))=""
	do ##class(XML.Element).Export(.elements, path_"/"table_".xml", "r")

And then you import it on the other instance with:


The advantage of this solution is that it uses %GUIDs as identifiers, as such you can add/edit data on your target system and it won't be overwritten when importing the file. 

An alternative way without having direct access to file system would be use a JDBC client with export functionality. I use DBeaver and you can right click on your query/table -> Execute -> Export from query:


Do you initialize your target variable as an instance of an object that has Name property? The following snippet works for me

Class Custom.Test Extends %RegisteredObject
Property Name As %String; 

ClassMethod SQL()
    set target = ##class(Custom.Test).%New()
    &sql(SELECT 'TestName' INTO :target.Name FROM MainFrame.EmployeeRecord)
    write target.Name

Also, assuming you are running your test in console, you can issue write $zerror it will tell you which property is missing (could be related to something in the source rather than the target)

Michael has not followed anybody yet.
Global Masters badges: