pTAL Conversion Guide

TAL Standard Routines
pTAL Conversion Guide527302-002
17-9
$OCCURS
$OCCURS
$OCCURS is a TAL routine for which pTAL has a built-in routine with the same name
but slightly different behavior.
$OCCURS returns the number of elements declared in an array.
identifier
is a variable, array, structure, or structure field. identifier cannot be the name of a
structure template.
In pTAL, if identifier is the identifier of an explicitly declared array—that is, it is not
a reference parameter—and identifier is the unindexed name of the array, $OCCURS
returns the number of array elements specified in the array’s declaration; otherwise,
$OCCURS returns 1.
Table 17-2 on page 17-9 and Table 17-3 on page 17-10 show values returned by
$OCCURS in TAL and pTAL. Because the TAL compiler handles structure arrays
differently than it does nonstructure arrays, structure arrays and nonstructure arrays
are in separate tables.
Table 17-2. $OCCURS for Nonstructure Arrays
$OCCURS Argument Example
$OCCURS Returns
In TAL In pTAL
Entire array INT a[0:9];
$OCCURS(a);
10 10
Value parameter or simple
variable
INT a;
$OCCURS(a);
1* 1
Reference parameter or pointer INT .a;
$OCCURS (a);
1* 1*
Array element using constant
index
INT a[0:9];
$OCCURS(a[3]);
The number of
elements in the array
1**
Array element using expression
in index
INT a[0:9];
$OCCURS(a[j]);
Compile-time error:
Constant Expected
1**
* The TAL compiler reports a warning that $OCCURS returns a constant value of 1.
**The native compiler reports a warning that $OCCURS returns a different value than TAL.
( )$OCCURS
VST103.vsd
variable