Previous Topic: $KEY FunctionNext Topic: $LOW Function


$LENGTH Function

$LENGTH is a numeric function that returns the length of the specified alphanumeric expression.

This function has the following format:

$LENGTH(alpha‑expression)
alpha-expression

An identifier comprising alphanumeric fields, groups, and functions. If you specify a variable length alpha field, the current length (as opposed to the maximum defined length) is returned.

Example

Assume that PARM_A is a variable length alphanumeric field defined in a calling program with current length 15 and a parameter in a subprogram defined with length 20. The following function in the called subprogram returns a length of 15.

$LENGTH(PARM_A)

Assume VAR is a variable length field defined with a maximum length of 11, and FIX is a fixed length field, also of 11.

SET VAR = 'VAR'
SET N = $LENGTH(VAR)
LIST N
3 will be returned.

SET FIX = VAR
SET N = $LENGTH(FIX)
LIST N

11 will be returned.