• 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
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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