|
|||||||
|
|
![]() |
|
|
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.
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |