Loading...
Select Version
&pagelevel(3)&pagelevel
Domain: String analysis
The LENGTH( ) function supplies the length of the specified string.
Format
LENGTH( ) |
STRING = string_expression |
Result type
INTEGER
Input parameters
STRING = string_expression
Designates the string whose length is to be requested.
Result
Number of type INTEGER
Error message
SDP1010 VARIABLE '(&00)' HAS NO VALUE
Example 1
/SET-VARIABLE A = 'ANNAMARIA' /SET-VARIABLE B = LENGTH(A) /SHOW-VARIABLE B B = 9
Example 2
/DECLARE-VARIABLE VARLIST,MULTIPLE-ELEMENTS = *LIST / VARLIST = *STRING-TO-VAR('(Terminal,Printer,Keyboard,Processor)') /SHOW-VARIABLE VARLIST VARLIST(*LIST) = Terminal VARLIST(*LIST) = Printer VARLIST(*LIST) = Keyboard VARLIST(*LIST) = Processor /FOR A = *LIST(VARLIST) / B = LENGTH(A) / SHOW-VARIABLE B /END-FOR
Output:
B = 8 B = 7 B = 8 B = 9
A list variable VARLIST is declared with default values. The first four elements of VARLIST are then assigned a value, in this case a word (the four values are specified in one assignment in this case, see the SET-VARIABLE command, "SET-VARIABLE Assign value to variable "). In the FOR loop, the length of each list element is checked and displayed.