Find the Length of a Character String in CL
October 19, 2005 Hey, Ted
Numerous times over the years, I’ve seen this question: How can I find the length of the value in a CL variable? That is, how many characters are in a variable, ignoring trailing blanks? I needed the answer often enough myself that I created my own “clever” way to handle it years ago by creating a RTNLEN command. But I recently discovered an alternative that’s been around forever. It uses a single command, RTVMSG, and it works for character variables up to 512 bytes long.
Here’s an example:
dcl &myvar *char 256 value('Abcd') /* Can be max *CHAR(512) */ dcl