%ELEM (Get Number of Elements)

%ELEM(table_name)
%ELEM(array_name)
%ELEM(multiple_occurrence_data_structure_name)

%ELEM returns the number of elements in the specified array, table, or multiple-occurrence data structure. The value returned is in unsigned integer format (type U). It may be specified anywhere a numeric constant is allowed in the definition specification or in an expression in the extended factor 2 field.

The parameter must be the name of an array, table, or multiple occurrence data structure.

Start of change The parameter cannot be a complex-qualified name. If you want to find the number of elements for a complex-qualified subfield, specify the data structure used in the LIKEDS keyword that defines the data structure subfield that contains the required subfield. For example, if you want to find the number of elements of INFO.CUST.ORDERS, and the CUST subfield of data structure INFO was defined with keyword LIKEDS(CUST_T), then specify %ELEM(CUST_T.ORDERS). End of change

For more information, see Array Operations or Built-in Functions.

Figure 1. %ELEM Example
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D arr1d           S             20    DIM(10)
D table           S             10    DIM(20) ctdata
D mds             DS            20    occurs(30)
D num             S              5p 0

 * like_array will be defined with a dimension of 10.
 * array_dims will be defined with a value of 10.
D like_array      S                   like(arr1d) dim(%elem(arr1d))
D array_dims      C                   const (%elem (arr1d))

 /FREE
    num = %elem (arr1d);  // num is now 10
    num = %elem (table);  // num is now 20
    num = %elem (mds);    // num is now 30
 /END-FREE