Newsletters Subscriptions Media Kit About Us Contact Search Home

Stuff
OS/400 Edition
Volume 2, Number 14 -- July 17, 2003

More on Edit Words


by Kevin Vandever

[The code for this article is available for download.]

In my last article, "Back To Basics: Edit Words," I gave an overview of edit words. I discussed the different components of an edit word, as well as the general rules that govern them. In this article I want to show you some practical examples and some of the complexities that go along with edit words. I am going cover each rule discussed in the previous article and provide the RPG example and printed output for each example. You might be surprised by their capabilities.

The Code and Output

First let's take a look at the RPG program, EditWords, which I wrote to generate my examples. It is a pretty simple program, and I included it so you could download the program and mess with edit codes themselves. Now that you've looked at the code, check out the printed output that is generated from that code. From these two documents, you should be able to follow along with my discussion in this article.

The Examples

Let's jump right down to the output specs in the RPG program. What I've done is to "spit" out, in most cases, the same number, 567, using a variety of edit codes. In a few cases I have used a negative number (-567) or a larger number to indicate a phone number, but for the most part, I tried to use the same digits.

The first four examples cover some zero suppression and decimal point (.) rules. In each of the first four examples, you can see how to easily modify the way that zero suppression happens from all zeros being suppressed to a specific amount, all the way to none. Also notice that the zero suppression character--zero, in this case, but an asterisk (*) later on--takes the place of one of the digits and therefore doesn't add to the size of the edit word. The decimal point is placed in the edit word where you want it to appear in the resulting output. Because it is inserted in the edit word, the edit word will now be one character greater in size than the field to be edited.

The fifth example shows how an ampersand (&) placed in the edit word will replace the resulting position with a blank. Notice I replaced the decimal point so that my decimal is now separated by a blank space instead of a (.). The ampersand was also inserted into the edit word, as opposed to replacing a specific character.

Examples six and seven show how to use an asterisk as a zero suppression character instead of a zero. The same rules apply, but you may want decide, especially in the case of displaying currency, to use the asterisk as the zero suppression character. Notice the difference between suppressing every non-significant digit with asterisk and mixing zeros and asterisks, which may not be desired, but easy to do.

The next two examples show how to get a floating dollar sign ($) and a fixed dollar sign respectively. To get a floating sign, you need to place the dollar sign directly to the left of the zero suppression character. The fixed dollar sign is achieved by placing the dollar sign in the first position of the edit word.

The tenth and eleventh examples show how to insert commas into your numbers to make them easier to read. Commas (,) are inserted in the edit word, as opposed to replacing characters, and they are placed exactly where you'd insert them in an actual number. They work just like the decimal point. The cool thing is that they will only print if they are needed-- meaning that if they exist in the zero suppressed portion of the edit work (to the left of the significant digits), they will not show on the printed output. This is easily seen in example eleven of the printed output sample. Note that this phenomenon is not just for commas. Any character inserted in the edit word will print if there are significant (non-zero suppressed) characters to print. (This technique is used at the end of the article.)

The next four examples show how negative numbers are handled. Well, actually, the next three examples. The fourth is not really an automated way to handle negative numbers. Basically, if you use the negative sign (-) or the credit symbol (CR) in positions to the right of the right-most significant digit, these characters will print if the number is negative. The negative number indicators are placed after the right-most number so they will add to the size of the edit word. The cool thing is that they will only print if the number is negative. So, looking at example 14, even though the negative number indicator is still part of the edit word, it is not printed, because the resulting number is zero or greater. Notice the next example. This is to show you how special the negative number indicators are, as well as to show you some other cool things you can do. You can place any character to the right of the right-most significant digits and those characters will print--always. Notice I've used the constant Negative at the end of my edit word. This works great if the number is, in fact, negative, but it will also print if the number is zero or greater. You'd have to add condition logic and resulting indicators if you wanted the constant Negative or any other constant to show up if the number is negative. I'll show you when you might want to use constants in a bit, but just know that the negative number indicators are specialized constants in edit words.

The last four examples show some of the cool things you can do with edit words. The first of these four is a pretty simple and common way to edit a phone number. Characters other than commas and decimal points can be inserted in an edit word to edit numbers. The next example is a more complex way to edit a phone number, and uses a combination of rules I've already discussed. Looking left to right, I inserted a dash (-) to separate the last four digits of the phone number. Then I inserted an ampersand before the prefix of the phone number. This will insert a space in my printed output. In fact, that's what all the ampersands do. Then I insert the constant NO to precede the prefix and number portions of the phone number. I also insert a constant AREA in front of the area code portion of the number to indicate that this is the area code. The first character in the edit word is zero suppression character. Without this first character, the first constant, AREA, would not display. The next two examples do the same thing with dollar amounts and fixed dollar signs. The cool thing about the dollar examples is that if there are only enough digits to signify the cents, and not the dollars, only the CTS constant will be displayed.

So Much Editing, So Little Time

I have showed you an example or two using each rule of an edit word. There are many more gyrations of each rule, and I invite you to give them a try. You'll have to play around with these things a little bit and study the rules to see what makes edit words tick. I had fun trying to get some of the last few examples to work, but before you get too lost, check out the IBM RPG reference manual for some additional tips and techniques. So go forth, and the next time someone wants to download something to a spreadsheet because the editing is better, show them what you can do with edit words.


Sponsored By
ASNA

How Independent Computer Consultants is saving $50,000 with ASNA

Independent Computer Consultants, Inc. (ICC) is a software development and consulting firm specializing in writing and maintaining business solutions that interface with the AS/400. With over 40 years of cumulative RPG programming experience, they have recently switched to AVR as their development environment of choice. ICC credits AVR for their expansion into the more lucrative client/server market.

Originally, ICC specialized in AS/400 green screen-based applications, but with AVR and ASNA's data access tools they have experienced a great deal of success in writing and selling Windows applications. Their applications include front-end packages for portrait studios and jewelry manufacturers; a billing and standards package for the railroad industry; a lease track package for the real estate industry and an investment tracking package for financial firms. By entering into this new Windows market, ICC has experienced an annual increase in revenues of almost $50,000.

"Using AVR has not only been fun-it has also increased our capabilities. We are now a more versatile company capable of handling a variety of computer needs."
-Debbie Houser

Download your FREE copy of ASNA Visual RPG today!
www.asna.com/AVR_literature.asp


THIS ISSUE
SPONSORED BY:

Profound Logic Software
PKS Software
Damon Technologies
ASNA


BACK ISSUES

TABLE OF
CONTENTS
Building Applications with Ant

Swapping AS/400 User Profiles

IBM's Toolbox for Java Is Getting Better Every Day

More on Edit Words


Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Raymond Everhart
Joe Hertvik
Ted Holt
Marc Logemann
David Morris

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.