Creating Custom AS/400 Edit Codes
By Craig Pelkie
Over the past several years, many astute System/36 programmers have noticed a mysterious entry on their O-spec sheets or debugging template. That entry applies to column 38, "Edit Codes." The mystery is, what do edit codes 5 through 9, shown as "user defined," do?
User defined edit codes made their appearance with the System/38. Quite simply, you have five codes that you can define and use anywhere, in place of an edit word. Big deal!, you might say. Maybe it is, maybe not-but think of some examples. If you have employee records, you're probably using an edit word each time you print or display their Social Security Number. Or maybe you print telephone numbers, nicely formatted, with edit words. For manufacturing or distribution applications, you probably have a part number that needs editing. Applications dealing with foreign currency are another example where you now use edit words.
With a user defined edit code, you can once-and-for-all "encapsulate" the dreaded edit word into a simple edit code. You can then use your edit code like any of the other edit codes, such as "Z" (zero suppress), "Y" (date edit) or the other numeric edit codes.
Look At Them First
The first thing you should do is look at these codes, as they are currently defined. That's right, they are shipped as part of OS/400. User defined edit codes even have their own object type, *EDTD (edit description). These objects reside in library QSYS. They follow a very simple naming convention, QEDIT5 through QEDIT9. You can use the WRKOBJ command to verify their existence, and the DSPEDTD (Display Edit Description) command to look at their current (shipped) definitions. You can also review the shipped definitions in Appendix E of the Data Management Guide (SC21-9658).
When you display or look up the description, you will probably be surprised to see the number of parameters that comprise the edit description. Actually, the parameters can be used to create rather complicated edit words. The big advantage you have is that you can define these complicated edits in one place, and never have to code the edit word again on O or A specs.
At this point, you should review Appendix E in the Data Management Guide. Also, refer to the index entries for "edit code" or "edit codes" (apparently, IBM couldn't make up their minds) and read one of the sections on user-defined edit codes. Both references are the same (one is in the section for display files, the other for printer files).
How Are They Used?
I told you earlier that you can use the user defined edit codes in the same manner as any other IBM defined edit code. If you are using O-specs for either printer or display files (or disk files, I suppose, if you are storing edited values), you can simply code the number 5-9 in column 38 of the O-spec. If you are using A-specs for printer or display files, you use the keyword EDTCDE, with the edit code number enclosed within the parentheses.
Now, this is important, so be sure you understand: the effect of using a user defined edit code takes place at program compile or file create time. That is, for an RPG program, the user defined definition is retrieved at compile time and becomes part of the compiled program. If you later change the user defined edit description, the new description is not used, unless you recompile the program. The same rule applies for display or printer files that you create with user defined edit descriptions. The edit description is used at file create time. To make use of a changed description, you have to delete and recreate the file.
As far as compiling or creating a program or file that has user defined edit descriptions, you don't need to take any special steps. Because the definitions are in library QSYS, they are "always" available. Also, I assume that you can use these edit descriptions in S/36 Environment programs.
How To Create Your Own Definition
Creating your own user defined edit description is easy. You simply choose one of the existing edit codes, 5-9, delete it with the DLTEDTD (Delete Edit Description) command, then create your definition with the CRTEDTD (Create Edit Description) command.
Because there are only five codes that you can work with, you will want to have general agreement within your shop before you start creating your own. That is, you don't want to create a code, then have somebody else decide to use the same code for a different edit description, since their creation will destroy yours.
For a complete review of all of the parameters you can use, I refer you to Control Language Reference, Volume 3 (SC21-9777). Rather than go through the meaning of all of the parameters here, I will leave you with two examples that I created; you may be able to improve them.
Sample Edit Codes
The samples that I created were for a Social Security number edit and for a telephone number with preceding area code.
The command for the Social Security number is shown in 1. Please note that the lower case "b" is not part of the edit description and should not be keyed; it is shown here to represent a blank space.
The command for the Social Security number is shown in Figure 1. Please note that the lower case "b" is not part of the edit description and should not be keyed; it is shown here to represent a blank space.
The INTMASK parameter looks like an RPG edit word. The interesting part here is the FILLCHAR parameter. This is used to "refill" a zero character where zero suppression has occurred. For a Social Security number, the accepted convention is to display all nine digits of the number, even if the leading number (such as mine) is a zero. The INTMASK parameter will always suppress the leading zero; the FILLCHAR puts it back. This will also fill an all zero Social Security number with zeros, so you'll have to decide if you want that for an all-blank field.
The telephone number edit is shown in 2. Again, in the INTMASK, lower case "b" represents a blank space, which will be filled with numbers. The ")&" and "-" characters are used to format the telephone number. In this example, the LFTCNS (left constant) parameter is used to indicate that we want to have an opening (left) parenthesis. If the left parenthesis had been included in the INTMASK, it would not be printed or displayed, since the first substitution character comes after the opening parenthesis. The LFTCNS parameter is used to "force" a character string to the left of the edited field. You can specify up to 31 characters for the LFTCNS, so you might have put LFTCNS('Telephone: ('). If you do include left or right constants, you have to count the length of the constants as part of the width of the edited field, and allow enough space on your report or display for the entire field.
The telephone number edit is shown in Figure 2. Again, in the INTMASK, lower case "b" represents a blank space, which will be filled with numbers. The ")&" and "-" characters are used to format the telephone number. In this example, the LFTCNS (left constant) parameter is used to indicate that we want to have an opening (left) parenthesis. If the left parenthesis had been included in the INTMASK, it would not be printed or displayed, since the first substitution character comes after the opening parenthesis. The LFTCNS parameter is used to "force" a character string to the left of the edited field. You can specify up to 31 characters for the LFTCNS, so you might have put LFTCNS('Telephone: ('). If you do include left or right constants, you have to count the length of the constants as part of the width of the edited field, and allow enough space on your report or display for the entire field.
Give It A Try
Even if you don't want to create your own edit descriptions, you should review the supplied descriptions in Appendix E of the Data Management Guide. You might be able to use some of them in place of edit word coding that you are now using.
A final point to remember is that you should document any of the user defined edit descriptions that you change. If you install a new release of OS/400, the edit descriptions will be reset to the system supplied values, and you will have to delete and create your own definitions again.
Craig Pelkie works for Bits & Bytes in San Mateo, California. Bits and Bytes markets Facilities Scheduling software for midrange computers.
User Defined Edit Codes
Figure 1 Edit code for Social Security number
Figure 1: Social Security Number CRTEDTD EDTD(5) + INTMASK('bbb-bb-bbbb') + FILLCHAR('0') + TEXT('SSN edit code')
User Defined Edit Codes
Figure 2 Edit code for telephone numberFigure 2: Telephone Number CRTEDTD EDTD(6) + INTMASK('bbb)&bbb-bbbb') + LFTCNS('(') + TEXT('Telephone edit code')