%LEN (Get or Set Length)

%LEN(expression)
%LEN(varying-length expression : *MAX)

%LEN can be used to get the length of a variable expression, to set the current length of a variable-length field, or to get the maximum length of a varying-length expression.

The parameter must not be a figurative constant.

Note:
  • For alphanumeric data, %LEN always returns the number of bytes.
  • For UCS-2 fields and graphic data, %LEN always returns the number of double bytes.
If you want to know the number of natural characters in the expression, use %CHARCOUNT instead. For example, the UTF-8 value 'ábç' has five bytes, but three characters.

   DCL-S fld1 VARCHAR(10) INZ('ábç');
   DCL-S n INT(10);

   n = %LEN(fld1);
   // n = 5

   n = %CHARCOUNT(fld1);
   // n = 3

For more information, see Size Operations or Built-in Functions.