Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions page (login required).


Returns the number of elements in a list.




list An expression that evaluates to a valid list. A Caché list must be created using ListBuild or ListFromString, or extracted from another list using List. The null string ("") is also treated as a valid list.


ListLength returns the number of elements in list. It counts all elements in a list, regardless of whether the element has a data value.


The following example demonstrates how to use the ListLength function:

myList = ListBuild("Red","Blue","Green","Yellow")
Println ListLength(myList) 'prints 4
Copy code to clipboard

The following example shows that ListLength counts all list elements:

GapList = ListBuild("Red",, "Green", "Yellow")
UndefVarList = ListBuild("Red",x, "Green", "Yellow")
NullStrList = ListBuild("Red","", "Green", "Yellow")
Println ListLength(GapList)        ' prints 4
Println ListLength(UndefVarList)   ' prints 4
Println ListLength(NullStrList)    ' prints 4
Copy code to clipboard

The following example shows how ListLength handles the null string and a list containing only a null string element:

Println ListLength("")       '  prints 0
NullList = ListBuild("")
Println ListLength(NullList) '  prints 1
Copy code to clipboard

See Also