Serialize JSON from SQL Row
Hey Community,
my Caché Version is 2013.1 and I can't update now.
I want to serialize a SQL Answer row into an Array filled with objects and then convert it to json.
Actually I use the following, which is very error prone when I have to do that often:
set list = ##class(%Library.ListOfDataTypes).%New()
&sql(
declare queryONLWK01 cursor for
select F0103, F0104
into :articlenumber, :amount
from GL.ONLWK01
where F0001 = :BET and F0002 = :DEB and F0003 = :MIT
)
&sql(open queryONLWK01)
&sql(fetch queryONLWK01)
while (SQLCODE = 0) {
set articleObject = ##class(%ZEN.proxyObject).%New()
set articleObject.articlenumber = articlenumber
set articleObject.amount = amount
do list.insert(articleObject)
}
}
I want to have the answer DIRECTLY in a list filled with objects from the select command like that:
&sql(declare queryONLWK01 cursor for
select F0103 as Articlenumber, F0104
into myList
from GL.ONLWK01
where F0001 = :BET and F0002 = :DEB and F0003 = :MIT)
myList = [{"Articlenumber": "15058455","F0104": "1"},{"Articlenumber": "95058458","F0104": "2"}]
set x = ##class(%ZEN.Auxiliary.jsonArrayProvider).%WriteJSONStreamFromObject(.json,myList)
Is it possible to get the answer I want direct into myList or a JsonString ?
Best regards