Array collection of Cache class

Caché

How to get a input in array collection with class properties.

 

Class collect.arraylist Extends %Persistent
{

Property DOB As %Collection.ArrayOfDT;

ClassMethod valu()
{
list = ##class(collect.arraylist).%New()
""your DOB:", DOB1
do list.arraylist.SetAt("DOB1",0)
}
 

Answers

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:

Property DOB As array Of %Date;

 

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
}