As the year 2000 approaches, AS/400 programmers are feeling an increasing urgency to ready old applications for the big day. Fortunately, a good selection of analysis tools exists to help you identify the fields, files, and programs that need changing. However, if you make your coding changes using a 5250 terminal or PC emulation, your choice of editors is limited - most third-party products on the market today provide their function through a Windows interface. Enter the Advanced Editor from Application Genesis, a green- screen RPG III and RPG IV source code editor that, on top of traditional edit facilities, provides a rich set of code-navigation capabilities.
In this article, I use a simple journal input program to demonstrate how you can use the Advanced Editor to edit an RPG program. A code generator created the original sample code, and the program works in classic AS/400 "work with" style over a journal detail file. The program uses two database files: the Journal detail file and the Chart of Accounts master file (used for account validation). The Journal file has two date fields: a journal entry date (DJNLE) and a posting date (DJPOST), both of which are in six-digit yymmdd format. These fields have just been changed in the database to the date data type, and the RPG program has been converted to RPG IV syntax to allow the use of date-aware opcodes (e.g., MOVE, MOVEL, ADDDUR, SUBDUR). We'll use the Advanced Editor to replace a call to a date-conversion API with a MOVE operation.
Using the Advanced Editor
You invoke the Advanced Editor from an AS/400 command line, using the EDTSRC command and specifying the source file you want to work with as follows:
EDTSRC SRCFILE(library/file) +
MBR(member)
Alternatively, you can create an option for the Advanced Editor in Programming Development Manager (PDM) and invoke the editor from there.
Once the source has been loaded into the work space, the product displays a screen like the one in Figure 1. In the upper-left corner, the panel specifies "Edit" to indicate edit mode (in the future, the product will also support a "View" mode). This line also names the source file, library, and member being edited or viewed.
The panel uses the following mode indicators to describe the editing session (you can see several of these indicators in Figure 1's upper- right corner):
Indicator Mode Ck Syntax checking is active. Tab Auto-Tab conversion is active. lo The edit area is in mixed-case mode. HI The edit area is in uppercase mode. Cvt Auto-Case conversion is active. == The code appears in normal (expanded) mode. >< The code appears in compressed mode (explained later).
Navigating Through a Program
The Advanced Editor provides several simple commands that let you move easily through a program to make your changes. To go directly to a particular part of the code, you use the Gosub command, or G for short. For example, to position the display to the first executable C-spec, you enter the following on the panel's command line (line 2):
G *MAIN
To display a subroutine, you key a G in the sequence number field of the program line that calls the routine. For example, to display subroutine SF1, which is called on line 95.00 of the sample program, you type a G as shown in Figure 2. The resulting screen displays the statements between the BEGSR and ENDSR statements for SF1. The screen's Top and Bottom function keys and commands operate against the subroutine's boundaries.
You can enter the G command as many times as necessary to navigate a program. As you move deeper into a program's structure (e.g., by following a series of nested subroutine calls), the Advanced Editor keeps track of where you are in the structure. For example, Figure 3 shows the screen displayed when you enter the G command against SF1DSP, a subroutine called by routine SF1. Notice the area to the right of the LEVEL: heading in the panel's upper- right corner. This field, which was blank on the earlier screens, now contains two values: SF1DSP is the level name the name of the currently displayed subroutine (or reference argument, explained later). And 2 is the drill-down number the number of levels we've drilled down, or followed, in the program's structure. The Advanced Editor increments and decrements the drill-down number automatically as you move through a program.
By pressing F12, you can backtrack level by level through a program. Or, to return directly to the starting point of a drill-down session, use the G command. For example, let's say you began at subroutine SF1, drilled down through six lower-level subroutines to subroutine PRTLIN, and now want to check some detail back in SF1. The command
G SF1
takes you directly to subroutine SF1. From there, pressing F12 returns you to the point where you entered the G command (i.e., to subroutine PRTLIN).
Special G-command values let you position the display to one of the other main RPG sections, such as the file definitions. For example, to display the first F-spec, you enter the command
G *1FILE
(The 1 indicates you want to position the display to the first F-spec.) Pressing F12 on the resulting panel returns you to the point where you keyed the command.
Locating References
Two other Advanced Editor commands supplement the G command's code-navigation capabilities. The Reference command (R for short) lets you quickly locate references to specific arguments in your code. You enter the R command on the editor's command line, specifying the argument you want to search for. You can issue the R command against any entity in a program's source - files, fields, data structures, subroutines, indicators, and literals. The resulting display lists any noncomment statements containing the specified search argument. All editing functions are available from the reference list display.
Once you've used the R command to locate a reference you're interested in, you can enter the Jump (J) command in a statement's sequence number field to position the display to the selected statement. The resulting panel shows you the portion of the program beginning with that statement.
Both the R and J commands cause the Advanced Editor to increment the drill-down number; pressing F12 therefore returns you to the display from which you entered either command.
Making the Change
Now, let's turn our attention to the task at hand: using the Advanced Editor to make the changes to our program. To find all occurrences of the journal entry date field, DJNLE, we enter
R DJNLE
on the command line of any display. The resulting screen (Figure 4) displays each program line that references DJNLE.
To keep this demonstration simple, let's consider only statement 560.00. When we enter the J command against this statement (by keying a J in the sequence number field), the Advanced Editor brings up the screen in Figure 5. As you can see, this part of the program uses the QWCCVTDT (Convert Date and Time Format) API to convert the date fields to a display format. Because the dates are now stored as date data types, we can replace each API call with a MOVE statement.
Let's assume that shop standards require us to comment out existing code when changing a program. To comment out the API operation, we simply key an asterisk (*) and at least one space starting in position 7 of each line of obsolete code. Then, to insert the new MOVE, we use the Insert (I) command on line 562.00 and key in the MOVE statement as shown in Figure 6. You might think that's a typing mistake between lines 562 and 563, but the line shown is in fact quite correct. An Advanced Editor function called Auto-Tab takes an inserted free-format C-spec, such as the one in Figure 6, and correctly parses it into the appropriate columns in the RPG program. Another Advanced Editor function, Auto-Case, automatically changes characters entered in lower case to upper case, except where you've enclosed the characters in quotation marks. Auto-Case converts all noncomment statements, whether they're being inserted or changed. (You can turn on or off the Auto-Tab and Auto-Case functions independently if you choose to.)
To have our changes take effect, we press Enter. Figure 7 shows the newly modified code.
Other Features
This example demonstrates just some of the features the Advanced Editor provides to simplify RPG editing tasks. The product can also
As you can see, the range of functions the Advanced Editor provides is both comprehensive in scope and powerful in function, helping to significantly enhance programmer productivity. For more information about the Advanced Editor, contact Application Genesis. (For pricing and vendor contact information, see "Product Information.")
Product Information
Advanced Editor 1.0
Source code editor
Platform
AS/400 at V2R3 or higher
Price
$795 per AS/400
Vendor
Application Genesis (Australia)
(61) 2-9653-2742; fax (61) 2-9653-2743
E-mail: 100252.2767@compuserve.com
Demo Booth provides a practical, technical look at application development and systems management/operation tools. In Demo Booth, software vendors provide concise, concrete explanations of how their products can solve common AS/400 problems. The vendors speak for themselves NEWS/400 technical editors referee submissions to eliminate promotional material, but vendors select their own problems, solutions, and styles of presentation. |