• 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:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • 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 iSeries Sales Down 18 Percent in Q4 as Users Await i5s and V5R4

    Leave a Reply Cancel 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

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

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