Array collection of Cache class
How to get a input in array collection with class properties.
Class collect.arraylist Extends %Persistent
{
Property DOB As %Collection.ArrayOfDT;
ClassMethod valu()
{
s list = ##class(collect.arraylist).%New()
r ""your DOB:", DOB1
do list.arraylist.SetAt("DOB1",0)
}
Comments
1. Define your collection property like this:
Class collect.arraylist Extends %Persistent
{
Property DOB As Array of %Date;
}Instead of "Array" you can also use "List". Documentation.
You can use Caché Studio > New Property wizard to get correct definition of "collection" property, select options - "A collection of Type" = array/list , "Containing elements of type" = %Date.
It then creates a definition:
You can set and access array data as follows:
ClassMethod Test()
{
// Get values
Set obj=##class(collect.arraylist).%New()
Do obj.DOB.SetAt($h,"key1")
Do obj.DOB.SetAt($h-1,"key2")
Do obj.DOB.SetAt($h-2,"key3")
// Get values
Write "Count: ",obj.DOB.Count(),!
Set key=""
Set date=obj.DOB.GetNext(.key)
IF key'="" Write "Data:",!
while (key'="") {
Write key,?5,$zd(date),!
Set date=obj.DOB.GetNext(.key)
}
Write !,"Data at key2: ",$zd(obj.DOB.GetAt("key2"))
Quit
}
You can use Caché Studio > New Property wizard to get correct definition of "collection" property, select options - "A collection of Type" = array/list , "Containing elements of type" = %Date.
It then creates a definition:
You can set and access array data as follows:
ClassMethod Test()
{
// Get values
Set obj=##class(collect.arraylist).%New()
Do obj.DOB.SetAt($h,"key1")
Do obj.DOB.SetAt($h-1,"key2")
Do obj.DOB.SetAt($h-2,"key3")
// Get values
Write "Count: ",obj.DOB.Count(),!
Set key=""
Set date=obj.DOB.GetNext(.key)
IF key'="" Write "Data:",!
while (key'="") {
Write key,?5,$zd(date),!
Set date=obj.DOB.GetNext(.key)
}
Write !,"Data at key2: ",$zd(obj.DOB.GetAt("key2"))
Quit
}