How to find length of a String in a variable?

Hi,

I want to find the length of a string in a char variable. The string can have a combination of numbers and alpha, even blanks.

I think we dont have a length function in Natural. Is there a way to find it, as a temp fix i am padding some pattern chars at the end of the string using COMPRESS and EXAMINE the position of pattern chars.

Thanks!!!

define data local
 1 #string(A32) init<"abc 123 def">
 1 #len   (I04)
end-define
*
examine full #string for ' ' giving length #len
write #len
*
end

if you are reading the content from a file or otherwise have a dynamic variable, there is a length function:

define data 
local
 1 #string(A32) init<"  abc 123 def"> 
 1 #dyn (A) dynamic
end-define 
*
compress #string into #dyn leaving no space
* or - *trim removes leading and trailing spaces...
#dyn := *trim(#string)
*
write *length(#dyn)
* 
end

Thanks a lot for the replies. :smiley:

we need to create Java service with above code and we have to use in flow service right …? dont mind for silly question , actually I am fresher trying for the same

Thank you