Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the length of character type variable in RPGLE?

Is there any easy way to directly return the length of character and type variable in RPGLE? The length I am talking about here is not the length specified in the D-spec. I am talking about the actual number of meaningful characters in a string. Let's say a character type variable is defined to be 50 characters long, and it is assigned with value 'Hello world!', then the length I want is 12, which is from 'H' to '!'. The leading and trailing blank is ignored. Is there any simple way to do this?

like image 295
God_of_Thunder Avatar asked Nov 30 '22 15:11

God_of_Thunder


1 Answers

You can use %len(%trimr(field)), which trims trailing spaces before checking the length.

  • %triml trims leading spaces (on the left)
  • %trimr trims trailing spaces (on the right)
  • %trim trims leading and trailing spaces
like image 173
dmc Avatar answered Dec 30 '22 12:12

dmc