LENGTH function
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Returns, as an INTEGER value, the number of characters, bytes, or columns in a string, an expression of type RAW, or a BLOB field.
Syntax
|
- exp
- An expression that evaluates to a CHARACTER, LONGCHAR, INTEGER, LOGICAL, or CLOB type. If exp evaluates to an INTEGER or LOGICAL, the STRING function is used to first convert it to a character string before returning the length. For a LOGICAL, YES/TRUE returns 3 and NO/FALSE returns 2.
- raw-exp
- A function or variable name that returns a RAW value.
- blob-field
- An expression that evaluates to a BLOB field.
- type
- A character expression that indicates whether you want the length of
exp in character units, bytes, or columns. A
double-byte character registers as one character unit. By default, the unit of
measurement is character units.
There are three valid types:
"CHARACTER","RAW", and"COLUMN". The expression"CHARACTER"indicates that the length is measured in characters, including double-byte characters. The expression"RAW"indicates that the length is measured in bytes. The expression"COLUMN"indicates that the length is measured in display or print character-columns. If you specify the type as a constant expression, ABL validates the type specification at compile time. If you specify the type as a non-constant expression, the AVM validates the type specification at run time for a multi-byte codepage..
Note: The expression"COLUMN"is not valid for a LONGCHAR variable or a CLOB field.
Examples
This procedure produces a report that contains item information. Because the information on the report fills the entire width of the screen, this procedure shortens the information in the description field for each item. If the description of an item is longer than eight characters, the procedure converts the description to the first eight characters followed by ellipses.
r-length.p
|
In this procedure, the LENGTH function returns the number
of bytes in the Name of number 29. The procedure returns a
15, the number of bytes in the Name, Bug in a Rug-by.
r-rawlen.p
|
Note
If the value of the expression is the Unknown value (?), the LENGTH function returns the Unknown
value (?).