Question

How can you tell if an array is empty or even what it contains? I know those are two different questions. Please be kind.

I instantiate the array this way:

local array MyFiles[1,5]
nFilesFound = ADIR( MyFiles, qazMSG + '*.*')
Was it helpful?

Solution

To check whether an array is empty takes two steps. First, you check whether there's only one element:

Then, you have to check whether the data in that element is empty by whatever standards make sense in content. So, in general, you might use something like:

IF ALEN(aMyArray) = 1 and EMPTY(aMyArray)
  * Array is empty
ENDIF

But in some situations, the first element being empty might be valid.

In the case you show, it's much easier. The function ADIR() returns the number of files found. So you can just check nFilesFound to see whether it's 0.

To try to answer your other question, you can see the shape of an array with the ALEN() function:

ALEN(aMyArray) or ALEN(aMyArray, 0) tells you the total number of elements in the array.

ALEN(aMyArray,1) tells you the number of rows in the array.

ALEN(aMyArray,2) tells you the number of columns.

You can multiply those last two to get the first.

Tamar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top