Newsletters Subscriptions Media Kit About Us Contact Search Home

Stuff
OS/400 Edition
Volume 2, Number 13 -- June 19, 2003

Back To Basics: Edit Words


by Kevin Vandever

You might have looked at the title of this article and thought, "edit words? Who needs to read about edit words?" I understand that a little. We as programmers have used them for years to display data on our reports and display screens, and have never needed to study them. However, it may surprise you to know that there is more to Edit Words, and if you'll take the time to dig a little deeper, you might just learn something new about them.

Most of our numeric editing can be accomplished using the edit codes provided by IBM. These codes allow us to properly place decimals, suppress leading zeros, and show if a number is a negative value. However, sometimes the edit codes provided by IBM are not enough. In those cases, we can use character literals as templates and apply those templates to numeric source values and produce edited output. Edit words allow us to add blank spaces, properly place commas and decimal points, suppress unwanted zeros, add leading asterisks and other constants, output a negative sign, and appropriately place a currency symbol. Once you start looking at them, you'll notice that they can get quite complicated.

My goal in this article is to introduce you, or re-introduce you, to the concepts of edit words. This will give you a basic understanding. In the next article, I will dig in and show you how powerful and even complex edit words can be, but also how you can produce some awesomely edited output for your customers and users.

Edit words are coded in RPG IV in one of three ways. First, you can simply define an edit word in positions 53-80 of an output specification. The edit word must be started and ended by an apostrophe. You can also create an edit word by creating a named constant in the data specification and using that named constant in positions 53-80 of the output specification. The newest way to apply an edit word is to use the new built-in function, %EditW. How to code edit words is usually not where people get tripped up or fall short, it really understanding how to create an edit word that is the problem.

Edit Word Components

Believe it or not, there are three separate components to an edit word: The body, the status, and the expansion. Below is an explanation of each component.

The body is the space for the edited result. It begins at the leftmost position of the edit word and ends with the rightmost character that can be replaced by a digit. The number of blanks (plus one zero or an asterisk) in the edit word body must be equal to or greater than the number of digits of the source data field to be edited.

The status defines a space to allow for a negative indicator. This indicator can be defined by using either the letters CR or a minus sign (-). If the unedited data is positive, the status positions are replaced by blanks. Edit words without the CR or - indicators have no status positions; that is, they are ignored. The status must be entered after the last blank in the edit word. If more than one CR follows the last blank, only the first CR is treated as a status; the remaining CRs are treated as constants. For the minus sign to be considered as a status, it must be the last character in the edit word. More on that later on.

The expansion is a series of ampersands and constant characters entered after the status. Ampersands are replaced by blank spaces in the output while constants are output as is. If status is not specified, the expansion follows the body.

Now For Some Rules

It's time to look more closely at the body of an edit word and how certain characters control how the resulting data is formatted.

A blank in the edit word is replaced with the digit from the corresponding position of the data field.

A zero (0) is used to stop zero suppression.  The default is that all leading zeros are suppressed, so by placing a zero somewhere in the edit word, you can control zero suppression. You place the zero in the rightmost position where zero suppression is to take place. Any leading zeros up to and including the position of the corresponding zero in the edit word will be suppressed. If you do not want any leading zeros suppressed, make the edit word larger than the data field and place a zero in the first position of the edit word.

An ampersand (&) causes a space in the corresponding position of the edited field.

 

An asterisk (*) is used for zero suppression just like the zero above, and the same rules apply to it. The added benefit is that an asterisk replaces each suppressed zero.

A dollar sign ($) in the edit word placed immediately to the left of the zero suppression code causes the insertion of a dollar sign in the position to the left of the first significant digit. This is called a floating dollar sign. A fixed dollar sign is a dollar sign that always appears in the first position of the edited field, regardless of the number of significant digits. To create a fixed dollars sign, simply place it in the first position of the edit word.

Commas and decimal points placed in the edit word are printed in the edited output in the same relative positions in which they were written unless they are to the left of significant digits.  If zero suppression has not been stopped, either spaces or asterisks will replace them, depending upon the method of zero suppression specified.  Other than the fixed dollar sign, any characters that precede the first non-zero digit position will always be suppressed.

All other characters used in the edit word are printed if they are to the right of the non-zero digits in the data field.  If they are to the left of the first non-zero digit in the data field, spaces or asterisks will replace them. The letters CR or the minus symbol (-) placed on the rightmost position of the edit word (the status component) will be printed if the source value is negative.  If the source value is positive, they will be replaced by spaces.

If there are more digit positions in the edit word than there are digits in the field to be edited, leading zeros will be added to the field before editing.

Thought You Knew Edit Word, Huh?

As you can see, edit words can get quite complicated. You might also realize that really, really understanding them will not only provide you with a powerful tool, but also impress your users and customers as well. In the next issue, I am going to expand on the edit word and show you many examples as well as some potential traps to avoid when using edit words. I think it's about time you get reacquainted with an old friend and find out how that friend can add oomph to your business applications.


Sponsored By
PROFOUND LOGIC SOFTWARE

RPG Smart Pages

If you are an RPG developer and want develop e-Business or Intranet Applications, there is no better choice than RPG Smart Pages.

RPG Smart Pages (RPGsp) is a complete Integrated Development Environment and platform specifically designed for RPG programmers. RPGsp simplifies web development at every step of the development process. In a matter of minutes, you can create applications that would take days with traditional web development methods.

RPGsp's advantages over other methods include:
· Intuitive RPG-aware Development Environment
· Uses native ILE RPG and standard HTML
· Wizards can build the initial application (RPG+HTML) vs. coding everything from scratch
· Full control over the page design and the business logic
· Includes a complete iSeries-aware Visual Designer, which requires little or no manual HTML coding
· Integrates a full-featured RPG editor
· Super fast (both development environment and deployed pages)
· Easy to maintain
· Automated installation and server configuration - create functioning browser applications minutes after downloading the software

Download RPG Smart Pages (RPGsp) today at www.ProfoundLogic.com.


THIS ISSUE
SPONSORED BY:

T.L. Ashford
Damon Technologies
WorksRight Software
Profound Logic Software


BACK ISSUES

TABLE OF
CONTENTS
Making HTML as Functional as a Green Screen

Data Entry Robots

Dr. Programmer, Private Eye

Back To Basics: 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.