Finding the length of data items
You can use the LENGTH
function
in many
contexts (including tables and numeric data) to determine the length
of an item. For example, you can use the LENGTH
function
to determine the length of an alphanumeric or national literal, or
a data item of any type except DBCS. You
can also use the
BYTE-LENGTH
function to determine
the length of an item in bytes.
LENGTH intrinsic function
The LENGTH
function
returns the length of a national item (a literal, or
any item that has USAGE NATIONAL
, including national
group items) as an integer equal to the length of the argument in
national character positions. It returns the length of any other data
item as an integer equal to the length of the argument in alphanumeric
character positions.
Move Customer-name To Customer-record(1:Function Length(Customer-name))
BYTE-LENGTH intrinsic
function
The
BYTE-LENGTH
function
returns the length of a national item, an alphanumeric item, or a
DBCS literal as an integer equal to the length of the argument in
bytes.
LENGTH OF special register
You
can also use the LENGTH OF
special register, which
returns the length in bytes even for national data. Coding either Function
Length(Customer-name)
or LENGTH OF Customer-name
returns
the same result for alphanumeric items: the length of Customer-name
in
bytes. The
BYTE-LENGTH
function
returns the same result as the LENGTH OF
special
register for all arguments types.
You
can use the LENGTH
and BYTE-LENGTH
functions only
where arithmetic expressions are allowed. However, you can use the
LENGTH
OF
special register in a greater variety of contexts. For
example, you can use the LENGTH OF
special register
as an argument to an intrinsic function that accepts integer arguments.
(You cannot use an intrinsic function as an operand to the LENGTH
OF
special register.) You can also use the LENGTH
OF
special register as a parameter in a CALL
statement.
Performing arithmetic
Creating variable-length tables (DEPENDING ON)
Processing table items using intrinsic functions


LENGTH (Enterprise COBOL for z/OS Language Reference)
LENGTH OF (Enterprise COBOL for z/OS Language Reference)