• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How Do I De-Edit? Let Me Count The Ways

    July 30, 2014 Ted Holt

    I’m sure that you, the professional that you are, are expert in the process of editing numbers. Unlike me, you may even have memorized the edit codes we often use in RPG and DDS source code. Editing is important because it makes life easier for the folks who use the software we produce. But do you know how to de-edit?

    These days data comes from many sources, and the people who send us this data (or from whom we glean it) don’t always give it to us in tidy packages. Converting such data to a usable format can be challenging, but of course, that’s no big deal for you, the professional that you are, because just as you’ve mastered editing, you’ve also mastered de-editing.

    De-editing means removing editing characters from a numeric string in order to extract the value. This means removing such things as currency symbols, thousands separators, negative number indicators, slashes, and hyphens.

    Let’s consider an example. Our RPG program has just read some text received from a Web service:

    You owe us $7,295,138.64. Pay now or else!

    How do we convert this dollar amount into something usable?

    The first thing we’d need to do is to extract the dollar amount. Since I am a big proponent of solving a problem once and re-using the solution, I would start by writing an RPG subprocedure to isolate the dollar amount.

    P ExtractDollars...
    P                 b
    D                 pi            24a   varying
    D  inText                      256a   const
      // locals
    D FromPos         s              5u 0
    D ToPos           s              5u 0
    D WorkString      s             24a
    
     /free
         monitor;
            FromPos = %scan ('$' : inText);
            if FromPos <= *zero;
                return *blanks;
            endif;
            ToPos = %scan ('. ': inText: FromPos);
            if ToPos < FromPos;
               ToPos = %scan (' ': inText: FromPos);
            endif;
            if ToPos > FromPos;
               return %subst(inText: FromPos: ToPos - FromPos);
            endif;
         on-error;
            // do nothing
         endmon;
         return *blanks;
     /end-free
    P                 e
    

    This routine extracts the character string $7,295,138.64 from the text. Now it’s de-editing time. As before, solve the problem once and re-use the solution.

    P DeEditDollars   b
    D                 pi            24a   varying
    D  inText                       24a   varying const
       // locals
    D WorkVar         s             24a   varying
    D WorkVarLen      s              5u 0
    
     /free
         WorkVar = %scanrpl('$': '': %trimr(inText));
         WorkVar = %scanrpl(',': '': WorkVar);
    
         // remove trailing - or CR
         WorkVarLen = %len(WorkVar);
         select;
            when WorkVarLen > 1
            and %subst(WorkVar: WorkVarLen: 1) = '-';
               WorkVar = '-' + %subst(WorkVar:1: WorkVarLen-1);
            when %len(WorkVar) > 2
            and %subst(WorkVar: WorkVarLen-1: 2) = 'CR';
               WorkVar = '-' + %subst(WorkVar:1: WorkVarLen-2);
         endsl;
    
         return WorkVar;
     /end-free
    P                 e
    

    Now put it all together.

    D Text            s             80a
    D Amount          s             11p 2
    
       Amount = %dec(DeEditDollars(ExtractDollars(Text)):11:2);
    

    Voilá! The AMOUNT variable has the dollar value in a usable numeric format.

    COBOL programmers may find this process a bit easier. Under the 1985 standard, de-editing takes place when copying from an edited variable to an unedited variable.

    01  Edited-var         pic zz,zzz.99cr.
    01  Balance-due        pic s9(5)v99.   
    
        Move Edited-var to Balance-due
    

    I am annoyed when I use a credit card to pay for something via the Web and see tiny text demanding that I not leave spaces in the credit card number. What kind of a sorry, no-count programmer is it that can’t remove spaces from a character string?

    De-editing is important.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    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

    NGS:  NGS-IQ is the complete IBM i query, reporting, and analytics solution.
    System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2.
    COMMON:  Join us at the COMMON 2014 Fall Conference & Expo in Indianapolis, Oct 27-29

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    SAP’s Q2 Bottom Line Pinched By Potential Lawsuit Charges OpenVMS Spinout A Possible Prelude To An IBM i Future?

    Leave a Reply Cancel reply

Volume 14, Number 17 -- July 30, 2014
THIS ISSUE SPONSORED BY:

Bug Busters Software Engineering
WorksRight Software
PowerTech

Table of Contents

  • Decisions, Decisions: Templates Or Snippets?
  • How Do I De-Edit? Let Me Count The Ways
  • When IBM i RGZPFM Doesn’t Want To Rebuild Access Paths

Content archive

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

Recent Posts

  • Positive News From The Kyndryl Mainframe Modernization Report
  • NAViGATE, inPower 2025 On Tap for September 2025
  • Guru: WCA4i And Granite – Because You’ve Got Bigger Things To Build
  • As I See It: Digital Coup
  • IBM i PTF Guide, Volume 27, Number 37
  • AI Is Coming for ERP. How Will IBM i Respond?
  • The Power And Storage Price Wiggling Continues – Again
  • LaserVault Adds Multi-Path Support To ViTL
  • As I See It: Spacing Out
  • IBM i PTF Guide, Volume 27, Numbers 34, 35, And 36

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