Newsletters   Subscriptions  Forums  Store   Career  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 5, Number 39 -- October 19, 2005

Find the Length of a Character String in CL


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 &l_myvar *dec (5 0) 
 
rtvmsg msgid(CPF9897) msgf(QCPFMSG) msgdta(&myvar) msglen(&l_myvar) 

And that's all there is to it. Use CPF9897 because it has no message text of its own--the returned length includes only the length of the supplied message data. It's far from perfect because of the length limitation; but for perhaps the majority of cases, it works very well.

--Tom Liotta, PowerTech


That's clever, Tom. Thanks for sending it in.

--Ted


Sponsored By
PRODATA COMPUTER SVCS

Finish first with DBU
and ProData utilities!

All ServerProven and on IBM's Roadmap

                                                                  DBU & DBU Audit
                                                                  DBUnifier
                                                                  SQL/Pro
                                                                  RPG Server Pages
                                                                  Stored Procedure Testing

Watch the i5/OS dragster at www.DoDBU.com


Technical Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.


THIS ISSUE
SPONSORED BY:

ProData Computer Svcs
iTera
DRV Technologies


Four Hundred Guru

BACK ISSUES

TABLE OF
CONTENTS
Find the Length of a Character String in CL

Bugged by the Interactive Debugger

Admin Alert: How to Change OS/400 Command Default Parameters


The Four Hundred
The "P" Word

IBM Gives Rebates and Trade Ins to Push the i5 520 in Q4

Why i for the Casino Industry?

Stop Arguing About Cars and Start Managing Fleets

Four Hundred Stuff
SEA and RevSoft End Partnership for OS/400 Utilities

BCD Aims to Streamline Report Writing with Clover

Tango/04 Looks for Database Changes with New Tool

Web Services and SOA Isn't Just Hype--It's Real, Magic Says

Four Hundred Monitor


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc. (formerly Midrange Server), 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement