• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • 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 &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


    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Midrange Dynamics North America

    With MDRapid, you can drastically reduce application downtime from hours to minutes. Deploying database changes quickly, even for multi-million and multi-billion record files, MDRapid is easy to integrate into day-to-day operations, allowing change and innovation to be continuous while reducing major business risks.

    Learn more.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Web Services and SOA Isn’t Just Hype–It’s Real, Magic Says iTera Says Out-of-Synch Conditions are a Thing of the Past

    Leave a Reply Cancel reply

Volume 5, Number 39 -- October 19, 2005
THIS ISSUE
SPONSORED BY:

ProData Computer Svcs
iTera
DRV Technologies

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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle