Question
· Sep 21, 2016

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()
{
list = ##class(collect.arraylist).%New()
""your DOB:", DOB1
do list.arraylist.SetAt("DOB1",0)
}
 

Discussion (3)0
Log in or sign up to continue

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
}

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
}