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 diagram
>>-SIZE(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);

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.

Start of changeWhen x is BASED and uses REFER, the compiler generates inline code for SIZE(x) if: End of change

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 */