Purpose
Returns the length of a string value.
Syntax
►►─┬─ STRING-LENGTH ─┬─ ( string ) ───────────────────────────────────────────►◄ └─ SLENgth ───────┘
Parameters
Specifies the string value whose length is determined.
String can be:
Example
In the following example, the length of a name contained in EMP-LNAME (PIC X(20)) is determined. To calculate the length of a string value, excluding leading and trailing spaces, the length function is used in conjunction with the extract function, as follows:
Initial value:
EMP-LNAME: 'SMITH '
Statement:
MOVE SLENGTH(EXTRACT(EMP-LNAME)) TO WK-NAME-LENGTH.
Returned string from extract function:
'SMITH'
Returned value from length function: 5
Note: If EXTRACT is called with an argument consisting only of spaces (x'40's), then it returns a string of one space. If that is passed on to the STRING-LENGTH function, the result will be 1.
Initial value:
EMP-LNAME:' '
Statement:
MOVE SLENGTH(EXTRACT(EMP-LNAME)) TO WK-NAME-LENGTH.
Returned string from extract function:
' '
Returned value from slength function:
1
|
Copyright © 2014 CA.
All rights reserved.
|
|