• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Handling Oversized Character Values Gracefully

    January 18, 2006 Ted Holt

    The FmtNum subprocedure has been very useful to me in dealing with oversized numbers. When I use FmtNum in a report program, it is obvious to anyone when a number has gotten too large for its allotted space. I suppose it was only a matter of time until I would need to show that a character value is too large for the space I had allowed for it. While chopping off the end of many character fields, such as customer names and inventory item descriptions, is no big deal, chopping of the end of others does present a problem.

    I encountered such a problem recently at my day job. The well-known ERP system we run allows more room than we use for most data values. I was cramped for space in the detail line of a report and was looking for places to trim some fat. However, I had to be sure that a certain alpha field value, the inventory item number, was not truncated.

    I considered several ways to indicate that a value was truncated, and finally decided to place a greater-than sign in the last position. For example, moving the value ABCDE to a four-byte variable yields the value ABC>. The routine is implemented as a function, returning a variable-length value of up to 256 characters. Since output fields on displays and reports are much shorter than 256 bytes, this limitation is in effect infinity. The first parameter is a variable-length string that is to be copied to the fixed-length destination.

    The second parameter is the length of the destination field or variable. This parameter is defined as a two-byte (three-digit) unsigned value. For more information about the numeric formats, see When a 10-Digit Variable Won’t Hold a 10-Digit Number.

    While I was preparing this routine for publication, it occurred to me that some folks might like to indicate a truncated value in a different way. For this reason, I added an optional parameter in which you can pass some other character to indicate truncation.

    Here’s the procedure prototype.

    D FmtChar         pr           256a   varying                
    D  inString                    256a   varying value          
    D  inLength                      3u 0 value                  
    D  inTruncChar                   1a   value options(*nopass) 
    

    Here’s the subprocedure itself.

    D/copy prototypes,FmtChar                                    
                                                                 
    P FmtChar         b                   export                 
    D                 pi           256a   varying                
    D  inString                    256a   varying value          
    D  inLength                      3u 0 value                  
    D  inTruncChar                   1a   value options(*nopass) 
                                                                 
    D TruncChar       s              1a                          
    D DftTruncChar    c                   const('>')             
                                                                 
     /free                                                       
        if inLength <= *zero                                     
        or %len(%trimr(inString)) <= inLength;                   
           return inString;                                      
        endif;
    
        if %parms() < 3;                                     
           TruncChar = DftTruncChar;                         
        else;                                                
           TruncChar = inTruncChar;                          
        endif;                                               
                                                             
        if inLength = 1;                                     
           return TruncChar;                                 
        else;                                                
           return %subst(inString:1:inLength-1) + TruncChar; 
        endif;                                               
     /end-free                                               
    P                 e
    

    Here are some examples of calls to FMTCHAR.

     /free
         ToField = FmtChar(FromField:%len(ToField));             
         ToField = FmtChar(FromField:%len(ToField):'-');         
     /end-free
    

    In the first assignment, a truncated value is indicated by a greater-than sign in the last position. In the second assignment, truncated is indicated with a hyphen. In each case, the size of the receiving field (or variable) is passed through the second parameter, ensuring that FMTCHAR is able to determine whether the value is truncated or not.

    I suggest adding this routine to a module of string-handling routines from which a service program is built, but I will leave it to the interested reader to implement the FmtChar function according to his or her good judgment.

    RELATED STORIES

    When a 10-Digit Variable Won’t Hold a 10-Digit Number

    Handling Oversized Numbers Gracefully

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    Lightedge

    Your IBM Power Cloud Strategy Should Start With “Why?”

    Moving IBM i to the cloud isn’t just an infrastructure decision.

    A hardware refresh, data center exit, IBM i skills gap, disaster recovery requirement, or broader cloud initiative can each lead to a very different architecture.

    At Lightedge, we start by understanding what you’re trying to accomplish. Then we look at the workload, application dependencies, resiliency requirements, operating model, and long-term strategy to determine where that workload belongs.

    Managed IBM Power cloud? IBM Power Virtual Server? DR in the cloud? A hybrid architecture connecting IBM Power with AWS or Azure?

    There isn’t one right answer for every IBM i environment.

    Start with the business requirement. Understand the workload. Then decide where it belongs.

    Explore IBM Power cloud, managed services, and hybrid solutions from Lightedge.

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Sponsored Links

    Bytware:  Network security, anti-virus, monitoring, notification/alerts, file recovery, & compliance
    ProData Computer Services:  Use Server Proven DBU-on-demand for $10 a day anytime, anywhere!
    COMMON:  Join us at the Spring 2006 conference, March 26-30, in Minneapolis, Minnesota

    IBM Creates New TCP/IP and Ethernet PTF Group WDSc’s Outline View is Handy

    Leave a ReplyCancel reply

Volume 6, Number 3 -- January 18, 2006
THIS ISSUE SPONSORED BY:

Profound Logic Software
WorksRight Software
COMMON

Table of Contents

  • Handling Oversized Character Values Gracefully
  • WDSc’s Outline View is Handy
  • Changing Object Authorities and Ownership for an Entire Library

Content archive

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

Recent Posts

  • IBM’s Bob AI Assistant Can Now Live In Your Datacenter
  • Start Where the Data Lives: Best Practices for Taking IBM i Into AI
  • Guru: A Modernization Experiment Using IBM Bob 2.0
  • How Are IBM i Shops Using AI? Fortra and COMMON Want to Know
  • IBM i PTF Guide, Volume 28, Number 34
  • It Is Time Once Again To Take The IBM i Marketplace Survey
  • PHP’s Evolution On The IBM i Platform Continues
  • Protecting IBM i Data For The AI Revolution
  • Guru: Two More Small But Handy RPG Enhancements: LIKE(*EXT) And %LOOKUPNE
  • IBM i Integration Gives Costco Shoppers Real-Time Inventory

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