SIZE

SIZE returns a FIXED BIN value that gives the implementation-defined storage, in bytes, allocated to a variable x.

Read syntax diagramSkip visual syntax diagramSIZE( x)
x
A variable of any data type, data organization, alignment, and storage class, except those in the following list:
  • A BASED, DEFINED, parameter, subscripted, or structure or union base-element variable that is an unaligned fixed-length bit string
  • A minor structure or union whose first or last base element is an unaligned fixed-length bit string (except where it is also the first or last element of the containing major structure or union)
  • A major structure or union that has the BASED, DEFINED, or parameter attribute, and that has an unaligned fixed-length bit string as its first or last element
  • A variable not in connected storage
The value returned by SIZE(x) is the maximum number of bytes that could be transmitted in the following circumstances:
  declare F file record input
          environment(scalarvarying);
  read file(F) into(x);
  • If x is a varying-length string, the returned value includes the length-prefix of the string and the number of bytes in the maximum length of the string
  • If x is an area, the returned value includes the area control bytes and the maximum size of the area
  • If x is an aggregate containing areas or varying-length strings, the returned value includes the area control bytes, the maximum sizes of the areas, the length prefixes of the strings, and the number of bytes in the maximum lengths of the strings.

The SIZE built-in function must not be used on a BASED variable with adjustable extents if that variable has not been allocated.

Under the CMPAT(V3) compiler option, SIZE returns a FIXED BIN(63) value. Under all other CMPAT options, it returns a FIXED BIN(31) value.

To get the number of bytes currently required by a variable, as opposed to the number of bytes allocated to it, use the CURRENTSIZE built-in function.

When x is BASED and uses REFER, the compiler generates inline code for SIZE(x) if:
  • Elements in x with the NONVARYING and BIT attributes have the ALIGNED attribute.
  • All other elements in x have the UNALIGNED attribute.

Example

  dcl Scids   char(17)         init('See you at SCIDS!') static;
  dcl Vscids  char(20) varying init('See you at SCIDS!') static;
  dcl Stg fixed bin(31);

  Stg = storage   (Scids);           /* 17 bytes */
  Stg = currentsize (Scids);         /* 17 bytes */
  Stg = size (Vscids);               /* 22 bytes */
  Stg = currentsize (Vscids);        /* 19 bytes */
  Stg = size (Stg);                  /* 4  bytes */
  Stg = currentsize (Stg);           /* 4  bytes */