06
Sun, Oct
2 New Articles

Beginner's Luck with AVR

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 I’d been using for the past 20 years. Maybe
I’ll switch to free-format code someday, but, then again, maybe I won’t, 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 you’ve been doing all this time,” said Steve. “I thought you’d been too quiet lately.”


“Amazing, isn’t it? And it’s 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 you’re supposed to be working on? Is it ready yet?” asked Steve.

“Not yet,” I replied. “But forget about that for a minute. Let’s talk about the future. I can really see using AVR for new projects!” All worked up at this point, I continued,
“You know, Steve, there’s an army of RPG programmers out there who have been doing the same stuff the same way for years. I think we’d better start offering users something else real soon. To be honest with you, even I’ve been Java’d to death.”

I immediately felt the wrath of Steve, Mr. Green-screen Eyes. “Listen,” he said. “I’ve 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 I’ll be impressed!” With that, he turned on his heel and left. “Come on, Frank. Let’s 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; it’s 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 you’ve 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, it’s 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 I’ll 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: “Where’s 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 X’00FFFFFF’ (white), and I change them to
X’000000FF’ (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 hasn’t,” 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 don’t 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 didn’t 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 RPG—Visual RPG!”


Beginner_s_Luck_with_AVR05-00.png 395x298

Figure 1: RPG does graphs!

Beginner_s_Luck_with_AVR05-01.png 395x297

Figure 2: The Demo program illustrates data entry and validation.


Beginner_s_Luck_with_AVR06-00.png 406x304

Figure 3: As you can see from this source code, much about RPG has changed, yet much remains the same.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: