Kunal Roy
Kunal Roy

Reputation: 787

How to find the length of the content of a string variable in rpgle?

Suppose I have a variable called VAR of size 50 character. This variable stores different vales at different instance of a loop. I want to know the length of the content it stores. Suppose in one instance it stores "My name is Kunal" in this particular case the length of the content of VAR is 16. Can some one help me with RPGLE logic which can help me get the length of the content.

Upvotes: 2

Views: 3271

Answers (2)

Barbara Morris
Barbara Morris

Reputation: 3674

As jtaylor___ said, use %len(%trim(var)) to get the length. Or use %trimr, %len(%trimr(var)), if the value might have leading blanks that should be counted as part of the length. For example, if the value is ' abc ' you might want the length 4, not 3.

Upvotes: 4

jtaylor___
jtaylor___

Reputation: 629

Assuming there aren't any leading or trailing blanks in your varChar(), use: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzasd/bblen.htm#bblen

If your variable is char(), you'll need to do a %trim().

Upvotes: 4

Related Questions