fhg
Volume 8, Number 41 -- December 3, 2008

There's Power in Edit Words

Published: December 3, 2008

Hey, Ted:

I am trying to use an edit word to insert hyphens into an account number. I must be doing something wrong, because leading zeros don't show up. I've used edit codes for years, but rarely edit words. Can you help?

--Laurie


You're not doing anything wrong. That's the way edit words work, Laurie. The system blanks out everything before the first non-zero digit, including editing characters. The good news is there's a way around it.

Let's illustrate with an example that many of your fellow readers will be familiar with: those nine-digit Social Security numbers without which Americans can't do anything.

The usual way to edit a Social Security number is to place hyphens after the third and fifth digits, like this: 123-45-6789. I don't know if any Social Security numbers begin with zero or not, but that's irrelevant to this illustration, so I'll assume they can.

The following code uses an edit word to insert the hyphens, as you are trying to with your account numbers.

D SSN             s              9p 0 
D EditedSSN       s             11a   
                                      
 /free                                
     EditedSSN = %editw(SSN:'   -  -    ');

This code works fine if the first digit is not zero, but fails otherwise. Look at the edited values in the following table.


Unedited number

Edited number

123456789

123-45-6789

12345678

  12-34-5678

12345

     1-2345

 


The trick is to place a zero in front of the first blank of the edit word. This makes the edited value one character longer, so you'll need to strip off the first character of the edited result.

D SSN             s              9p 0 
D EditedSSN       s             11a   
                                      
 /free
     EditedSSN = %subst(%editw(SSN:'0   -  -    '):2);

Here's the same table, with the new edit word applied.


Unedited number

Edited number

123456789

123-45-6789

12345678

012-34-5678

12345

000-01-2345

 


You can use edit words in RPG programs (output specs and the %EDITW built-in function), in DDS (in the EDTWRD keyword), and in the Convert Edit Word (QECCVTEW) API. IBM has packed a good bit of programming logic into edit words. It seems a waste not to take advantage of it.

--Ted




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


Sponsored By
HELP/SYSTEMS

SEQUEL™ -- IBM® System i™ Business Intelligence Made Easy

                  · Easy to use by IT and end users
                  · Automated data access and display
                  · Complete BI package: reports, tables, key performance indicators, and dashboards
                  · System i-centric for real-time data analysis
                  · Multiple interface options: graphical, green-screen, browser
                  · Expert support and training

SEQUEL meets your System i data access and analysis needs.

http://www.helpsystems.com/400g


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

ARCAD Software:  FREE Webinar, Managing IBM i and .NET Development, December 9
RJS Software Systems:  Make your office paperless with WebDocs
COMMON:  Join us at the 2009 annual meeting and expo, April 26-30, Reno, Nevada


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
How Big Blue Sees Small You

Smart Business Boxes Launch in India, Not the U.S.

IBM Hitches Business Continuity Horse to Managed Backup and Recovery Wagon

As I See It: The Difference Maker

Zend Framework 1.7 Includes DB2/400 Adapter

The Linux Beacon
Why Blade Servers Still Don't Cut It, and How They Might

Intel Keeps Both Arms Swinging with Xeons, Jabs with Itanium

Microsoft Ponies Up Another $100 Million for Novell Linux

Mad Dog 21/21: Newtonian Economics

Two More Xeon-Based Galaxy Servers from Sun

Four Hundred Stuff
IBM Unveils Change Management Software for System i

Pat Townsend Unveils Encryption Key Appliance

Micro Focus Updates Former NetManage Products

BOSaNOVA Revs Encryption Engine, Adds AES Support

NGS Waives License Fees for DB2 Web Query Alternative

Big Iron
For Some Customers, the Mainframe Is Green

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
November 29, 2008: Volume 10, Number 48

November 22, 2008: Volume 10, Number 47

November 15, 2008: Volume 10, Number 46

November 8, 2008: Volume 10, Number 45

November 1, 2008: Volume 10, Number 44

October 25, 2008: Volume 10, Number 43

The Windows Observer
Citrix Addresses Performance with XenApp 5

Server Buyers Shop Like It's 1999 in the Second Quarter

Intel Keeps Both Arms Swinging with Xeons, Jabs with Itanium

Mad Dog 21/21: Newtonian Economics

Microsoft Does Something About Those SQL Injection Attacks

The Unix Guardian
What the Heck Is the Midrange, Anyway?

Overseas and Notebook Sales Offset Printer Declines for HP in Q3

Two More Xeon-Based Galaxy Servers from Sun

Mad Dog 21/21: Newtonian Economics

Intel's Nehalems to Star at IDF, AMD Pitches Shanghai

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
Computer Measurement Group


Printer Friendly Version


TABLE OF CONTENTS
There's Power in Edit Words

SQL and Conversion Strategies

Admin Alert: Tuning i5/OS Storage Pools for Performance

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Insert via Java

iSeries Access for Web

Mimix installation and configuration docs

EDI Inovis Programmer - Heavy Duty Problem Solver - Anytime

Data Queues vs. MQ Series: Performance

Removing blanks from a CL Variable

XML





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement