Soon after I started the ASNA Visual RPG for Smarties tutorial, I was both hooked and doubly impressed with the product and especially with myself. Here I was, a forty- something-year-old programmer doing GUI programming in the language of my trade, RPG. In the past, I had often wondered how those other guys did GUI programming. I had tried looking at books on Visual Basic and even Java but had never been able to get past the first few pages. Well, now things were different!
ASNA Visual RPG (AVR) allows programmers to enter source code in either fixed or free format. Personally, I still prefer to enter code in fixed columns, and this is probably why I found it so easy to get started with AVR. With so many other things to absorb, it was nice to code applications in the structure Id been using for the past 20 years. Maybe
Ill switch to free-format code someday, but, then again, maybe I wont, since I learned that, although some operations require free-format code, you can always intermix it with your fixed-format code.
As soon as I finished the tutorial, I embarked on my own self-directed AVR learning course. Within a few weeks, I came up with a little graph program to show monthly item sales from our MAPICS XA database, although I have to admit that I did call the ASNA support line every day. They were more than helpful; one guy I talked to came from the same RPG background I did, so my questions seemed completely normal to him.
Pushing My Luck
With my new program up and running, it was time to show it to my boss, Steve, and fellow programmer, Frank, both of whom were dressed in the wool of RPG III programmers. Bubbling with excitement, I called them into my office. From debug mode, I clicked the Run function, and the program compiled. A few seconds later, a screen appeared and prompted me for an item number and starting year. Right away, a graph like the cute one in Figure 1 appeared.
What do you think? I asked both of them. Wow! said Frank. This is RPG?
Yes, it is, I replied. I clicked Stop and pressed F7, and up popped a page of code that looked somewhat familiar to Frank. I could see him studying it.
So this is what youve been doing all this time, said Steve. I thought youd been too quiet lately.
Amazing, isnt it? And its in RPG! I said proudly. Cute, said Steve, but how does a graph help the payables department? What are you talking about? I asked.
You know that check reconciliation program youre supposed to be working on? Is it ready yet? asked Steve.
Not yet, I replied. But forget about that for a minute. Lets talk about the future. I can really see using AVR for new projects! All worked up at this point, I continued,
You know, Steve, theres an army of RPG programmers out there who have been doing the same stuff the same way for years. I think wed better start offering users something else real soon. To be honest with you, even Ive been Javad to death.
I immediately felt the wrath of Steve, Mr. Green-screen Eyes. Listen, he said. Ive heard a lot about all these new technologies, but you show me a better way than 5250 screens to get data into our AS/400, and then Ill be impressed! With that, he turned on his heel and left. Come on, Frank. Lets get back to work.
Frank stalled for a moment and looked at me, still interested. Could you show me how data entry is done in AVR, kind of an introductory, 101 course?
Luckily, Frank Sees the Light
I think it was Einstein who once said, Learning by example is not one way to learn; its the only way. Well, to that I might add that the first part of the learning process is to try and relate what you already know to what is new and unknown. The episode I just recounted led to a little pseudo data entry program named Demo, a very uncomplicated little program that showed Frank how an AVR programmer could perform some of the basic and familiar duties of a data entry program.
This program is functionally equivalent to a typical 5250 RPG III data entry program in how errors are trapped and shown to the user. A typical data entry program shows the user a screen of data fields, and when Enter is pressed, a subroutine usually verifies the fields from top to bottom. As soon as an error is found, the screen is shot back to the user, with the cursor positioned in the particular field with the error, and the color is changed (usually to a reverse image). In addition, a message appears at the bottom of the screen with a description of the error. (In my old System/34 days, I would even set the buzzer on, but I had to give up that practice because too many people complained about the racket. Everyone in the office knew whether or not you were having a bad day by the amount of noise the buzzer made.)
The logic of Demo is simple. As shown in Figure 2, the program presents a screen with two I/O fields and an EDIT button. The EDIT button performs a subroutine the way a function key (e.g., F1 to F24 or KA to KY) does in green-screen programs. When you add a command button to a form, AVR generates an empty subroutine. You, the programmer, fill in code between BEGSR and ENDSR (just as youve been doing all these years). In AVR, every line of code before the first subroutine is executed just once as the program starts, much like in an initial subroutine.
Figure 3 shows part of the source code for Demo. I start by defining two colors for the I/O fields: white and red (for errors). To jazz things up and show a multimedia feature of AVR, sound, I open up a *.wav file. (In this program, its the crash sound.) The caption for the command button is EDIT, but I left its default name as CommandButton1. (Normally, you would change its name to EDIT or whatever best describes its intended function.) The CommandButton1 subroutine checks for field errors when EDIT is clicked. (Note: If you make the EDIT button the default button, it will be automatically clicked whenever Enter is pressed.)
I begin editing the input by testing to see whether or not the user entered a negative value. If the user did enter a negative value, I do the following:
1. Change the field color to red by moving red to IOFIELD1.
BACKCOLOR:
move red iofield1.backcolor
2. Send an error message to the screen by using the Message Box (MSGBOX) command:
msgbox iofield1 cannot be blank
3. Place the cursor in the field in error:
IOFIELD1.SETFOCUS()
4. Play the crash sound (just for fun):
WAVE1.PLAY()
5. Set indicator 90 on
If FIELD1 is in error, I LEAVE the subroutine and check FIELD2 once FIELD1 has been corrected. To show a blinking field, I use the timer control. If both fields are not negative, indicator 90 turns off and makes the No Errors label visible. (The label was invisible at design time.) The TIMER control is a new concept to traditional RPG programmers, and Ill skip a lengthy description of its function. I used it here merely to get a field to blink.
So I ran the Demo program for Frank. The first question he asked: Wheres the DDS? AVR does not use display file DDS. You design a program by inserting various controls into your forms. Some controls you can use are LABEL, IOFIELD, COMMANDBUTTON, SUBFILE, and TIMER. You can set the attributes of these controls at design time and modify them at runtime. For example, the two I/O fields are left with their default background colors as X00FFFFFF (white), and I change them to
X000000FF (red) if I detect a negative value. With DDS, I would set an indicator on to force the errant field to reverse its image.
This was where Frank started to catch on. It seems to me that a lot has changed, yet it hasnt, he said, and he was right. AVR programmers are not writing new Martian code; most of them come from an RPG III/IV background. What was learned then is being applied now, just within a new technology.
Frank watched me end the program by clicking the Stop button. I was in debug mode, which allows the programmer to design, write, and test a program before actually compiling it into a machine language executable program (.exe file). Wait a minute, Bob! said Frank with a quizzical look. Is that how you end a program?
I realized that this was an excellent time for Frank to work on his first AVR program, so I got up from my desk and made him take my seat. Good question, Frank! I said. Why dont you write the code to exit the program by using the good old-fashioned way of setting LR on.
With the program form on the screen, he brought the Control Palette to the front of the form, clicked the command button, and dragged it onto the form. With the mouse, he adjusted the size of the new control to his liking, then used the arrow keys to move this new control into place next to the EDIT button. (I later told him that there was a way to duplicate the EDIT button to ensure that both command buttons were the same size.) Since this new control had the focus, he pressed F4 to bring up the properties of this control and changed the CAPTION property to EXIT.
Now it was time to attach this new control to some RPG code. He pressed F7, and the code window came up. In the control box was CommandButton2. In the Events box, he clicked on the down arrow and selected the Click Event. The cursor automatically went
to the empty line between the automatically created BEGSR and ENDSR lines, and he entered the following:
C SETON LR
That was it. He pressed F5 to compile the program in debug mode and saw the results of his first visual rpg program change. The new control acted the same as F3=EXIT.
My Coming of Age
About this time, you might be wondering about data files. AVR can work with files on three platforms: AS/400, NT server, and PC. On the AS/400, you install DataGate/400; on the NT server, you install Accerler8DB; and, on a PC, you install client and RPG runtime modules. ASNA also allows you to access files on all three platforms at once if you want them. The files you create on the NT server are in the familiar AS/400 database format, and a tool is provided to create physical, logical, and join files. In addition, the client software on your PC allows you to manage your databases on all the platforms.
One day, as an experiment, I copied a few files from our AS/400 170 to our NT server and changed a few F-specs in a subfile program to make the subfile program look at these files on the NT server. At the time, our AS/400 was not in production, and I was the only user. I ran one copy of the subfile program on the AS/400, and the other copy I just modified on the NT server. The NT server was used mainly as a print-and-fax server, and I was quite surprised at its speed. It was almost impossible to tell which machine delivered my subfile data to the screen faster!
Once we went live on the new AS/400, however, there was no contest. The NT server was easily the winner. I then had to stop and think about all this, not only what this difference in speed between these machines could mean but also the simple fact that I really had come a long way. I could now easily develop applications in AVR, and the platform didnt matter. In other words, I, as an RPG programmer, could walk into a company that had NT technology and write full-feature applications in RPG.
Writing Well Is the Best Revenge
In the middle of all this, I had left the company where Steve and Frank worked. One day, I called Steve to see how it was going, and, after a little chat, I had to do it. I just had to say, You know, Steve, old programmers never die; they just keep on writing RPGVisual RPG!
Figure 1: RPG does graphs!
Figure 2: The Demo program illustrates data entry and validation.
Figure 3: As you can see from this source code, much about RPG has changed, yet much remains the same.
LATEST COMMENTS
MC Press Online