LENGTH Function

Purpose

Returns a Fixed Binary integer that gives the number of characters or bits in the specified string.

Syntax

LENGTH(s)

Parameters

s is a Character, Bit String, or Picture value. If s is a binary value, it is converted to a Bit string. If it is a decimal value, it is converted to a character string.

Description

The LENGTH function returns an integer that gives the number of characters or bits in the string s, where s is either a character string or a bit string. For character varying strings, this is the length of the string currently stored in the variable.

The precision of the result is Fixed Binary(15) unless the -bifprec compiler option overrides it. A null string has length zero.

Examples

    dcl s char (40) varying;
    dcl t char (40) ;

    s = 'The Lawn, 22-30 Old Bath Road';

    put skip list ('length(s) is: ', length(s));   /* char var */
    put skip list ('length(t) is: ', length(t));   /* char       */

will print:

length(s) is:          29
length(t) is:          40

Restrictions

None.