SIZE Function

Purpose

Returns a Fixed Bin(31) value that is the number of bytes allocated for the referenced variable.

Syntax

SIZE(reference)

Parameters

reference is a variable of any data type and storage class.

Description

This function is identical to the STORAGE function and is provided for compatibility with earlier versions of Open PL/I (formerly called LPI-PL/I).

The SIZE function returns a Fixed Bin(31) integer that is the number of bytes allocated for the referenced variable. The variable can be a scalar, an array, an array element, a structure, or a member of a structure. The reference cannot be made to a constant or an expression.

When a reference is made to an individual array element, the value returned is the size of the element of the array and not the size of the entire array. The SIZE function can be used with an unconnected array argument.

If the variable is a bit string that does not fill an integral number of bytes, the value returned is rounded up to the next byte. If the variable is of the type character varying, the value returned is the declared length of the string plus two, where the extra two bytes are the bytes needed to store the current length of the string.

Examples

In the following example, the returned values are shown in the comment.

Note: The sizes in the example are accurate for Open PL/I, but may not be correct for different implementations of PL/I that have different precision, alignment, boundaries, or datatype representations. For information on this implementation, see your Open PL/I User's Guide.
DECLARE
   S FIXED BIN(31), 
   A FIXED BIN(15),
   B FIXED BIN(31),
   C FLOAT BIN(23),
   D CHAR(5),
   E CHAR(5) VARYING, 
   F BIT(11),
   G POINTER;

S = SIZE(A);   /* S = 2 */
S = SIZE(B);   /* S = 4 */
S = SIZE©);   /* S = 4 */
S = SIZE(D);   /* S = 5 */
S = SIZE(E);   /* S = 7 */
S = SIZE(F);   /* S = 2 */
S = SIZE(G);   /* S = 4 */ 

DECLARE
   S FIXED BIN(31), 
   1 A_STRUCT
      2 A FIXED BIN(31),
      2 B CHAR (2), 
   C(20) FIXED BIN(15);

S = SIZE(A_STRUCT);    /* S = 6 */
S = SIZE(A STRUCT.A);  /* S = 4 */
S = SIZE(A_STRUCT.B);  /* S = 2 */
S = SIZE©);           /* S = 40 */
S = SIZE©(13));       /* S = 2 */ 

DECLARE
   S FIXED BIN(31),
   1 STRUC1,
      2 A BIT(1),
      2 B BIT(3);
DECLARE
   1 STRUC2,
      2 C BIT(1) ALIGNED,
      2 D BIT(3) ALIGNED;

S = SIZE(STRUC1);   /* S = 1 */
S = SIZE(STRUC2);   /* S = 2 */

Restrictions

None.