^SIZE

Return the size of an expression

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
size = ^SIZE(expression)

or

xcall SIZE(expression, size)

Return value

size

The size of an expression. (i)

Arguments

expression

An expression whose size will be returned. (a or n)

Discussion

^SIZE returns the number of bytes in the data area referenced by the specified expression. In Synergy .NET, ^SIZE can also return the size of a non‑descriptor type or the length of a System.String field.

^SIZE is especially useful in subroutines that handle arguments with variable lengths, because you usually need to know the length of an argument to control how its contents are processed. For example, ^SIZE would be helpful in a subroutine that parses an alpha argument to decode a command line. Because it’s evaluated at compile time, ^SIZE can be used on arguments referenced in the procedure division but not in the data division.

Subroutine arguments that have not been passed have a size of ‑1.

^SIZE of an array results in the size of one element of the array by default. You cannot use ^SIZE on arrays larger than 64K.

The following specifications,where idx and ndx are literals, are recognized as compile‑time constants.

^SIZE(dvar[ndx])
^SIZE(var(idx))
^SIZE(dvar[ndx](idx))

If you compile with the /DECSCOPE or ‑s compiler option, specifying ^SIZE of a real array or a pseudo array returns the size of the whole array.

In traditional Synergy, ^SIZE is functionally identical to %LEN. We recommend that you use the ^SIZE format, which is more efficient than the SIZE subroutine.

In Synergy .NET, ^SIZE can be used to obtain the size of an unmanaged type (sbyte, byte, short, ushort, etc.), in bytes. For example, ^SIZE(int) returns 4.

Examples

Assume the following data division statements:

record
    aa          ,a10,   "abcdefghij"
    bb          ,d6,    102507
    cc          ,d1,    4

Here are some examples using ^SIZE:

Function

Length

^size(aa)

10

^size(aa(5,7))

3

^size(aa(6:‑2))

2

^size(aa(bb(2,3),cc))

3

The following subroutine rotates the characters in what to the left. We used the ^SIZE function because there’s no way of knowing in advance how long what will be.

subroutine rotat
    what        ,a
record
    first       ,a1
proc
    first = what(1, 1)
    what = what(2, ^size(what))
    what(^size(what):1) = first
    xreturn
end