• 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
    Rocket Software

    Meet digital age demands while maximizing your IT investment.

    Future-proof your mission-critical applications with Rocket® Solutions for IBM® i that keep your business ahead of the curve.

    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

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

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