Sat, Apr
5 New Articles

Revving Up RPG for the Windows Generation

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

In the growing world of e-business and Internet-based applications, there is concern that green-screen programming will not survive in the IT industry. The concern is warranted, based on the rise in the percentage of AS/400 shops moving to Web-based software such as Lotus Domino and WebSphere.

So what is the RPG programmer to do with a language based on green-screen programming? The answer is actually pretty nice: Become a GUI programmer with IBM’s VisualAge RPG (VARPG). Doing so requires minimal additional op codes, and, therefore, a tiny learning curve. In this article, I introduce the keywords unique to VARPG (BEGACT/ ENDACT, SHOWWIN/CLSWIN, GETATR/ SETATR, and READS) and features of VARPG that you’ll need to understand to use the product.

To illustrate these keywords and features, I use an example project that creates a simple selection subfile. In this project, all the records of a small file called CONTACTS, which is described in Figure 1 (page 90), will be read and placed in a scrolling subfile. In RPG III or RPG IV, you would accomplish this by keeping track of the subfile record number, the number of records per screen, etc. In VARPG, the process is much simpler, because code is both Windows-based and action-based.

Windows-based vs. Screen-based Programming

What is so important about having code that is based on the Microsoft Windows operating system interface and on user action? Those wonderful little green-screen programs—albeit suitable to some tasks—leave users asking why they cannot point and click. Screen-based programming works on a drill-down principle. That is, the first screen should present the items a user most often requires. Other screens are used for less often required, supplementary data. As many programmers can attest, this principle tends to work until the screen enhancements are requested. Suddenly, pertinent information is found on screens that the programmer placed several levels deep because it was easier to code at a different level.

Windows-based programming is multifaceted programming. Everything is an object (also called a part). The icons on the desktop are objects. The taskbar and headers are objects. Entry fields and subfile lists are objects.

The most visible difference between a green-screen application and a GUI-based Windows application is that information is right at the fingertips of the Windows user while

the green-screen user has no idea how far he may need to go to get there. Sometimes, the green-screen user may not have a way of accessing the information he seeks. This has a lot to do with code being written on conditions rather than actions.

Conditional-based vs. Action-based Code

How are action programs so different from conditional programs? Action programs tend to behave in a manner similar to the way users think. As the rapid acceptance of the Internet has proven, the typical user tends to have a reason for moving from one task to another quite often. It may be that the user works in customer service, and as he is inputting data from the previous day, a customer calls wanting to know the status of an account immediately. The customer service clerk does not want to get out of a screen to answer the customer’s query; nor should the clerk have to put the customer on hold while he finishes entering the daily batches.

In the green-screen world, you can engineer an option to suspend batch entry to allow for just this type of situation. In the world of action programs, a window is suspended (or made inactive) while another window is made active to handle the customer issue. Once the clerk has satisfied the customer, data entry can resume quickly and with minimal interruption.

This is not to say that conditional programs are inferior to action programs. In fact, action programs are also conditional programs. A very good example is the install programs within the Windows environment. Almost all of them at some point have a Cancel and OK button on the same window. Clicking one of these buttons will cause an action routine to execute. Within the action routine a number of conditions may execute. For example, there may be multiple windows open that need to be closed. User interaction may be necessary before an action routine can continue. For example, a required field may have no value. Also, the Minimize, Maximize, and Close Window boxes generally found in the upper right-hand corner of your windows execute action routines. In short, conditional programs are not inferior to action programs: Action programs supplement conditional programs in a way that makes data more accessible to the user.


Now that I’ve discussed two features of the VARPG language, it is time to turn the focus to the keywords that give VARPG life beyond the world of the green-screens: BEGACT (Begin Action Subroutine) and ENDACT (End Action Subroutine).

These two keywords delimit the actions related to a part. These keywords perform in a manner similar to BEGSR and ENDSR. The biggest difference is that the BEGACT/ENDACT op codes respond directly to the actions of function keys, mouse buttons, or cursor movement as opposed to the top-down processing normally associated with RPG code. That is, a routine denoted by a BEGACT association with a push-button executes whenever a user pushes that button. There is no conditional op code used to execute an action subroutine. Execution is based on actions, not conditions.

It is worth noting, however, that BEGSR and ENDSR are not replaced in VARPG. There are still plenty of reasons to execute routines that do not respond to function keys or other associated Windows activities.


The SHOWWIN (Show Window) and CLSWIN (Close Window) keywords control whether or not a window is available for use. Note that the window can be available though neither active nor visible to the user. For example, suppose a program normally requires a password for data access, but the user has requested that the password be cached (or saved) so it is automatically used every time. In such a case, the password window may be active but not displayed for this user. These keywords control only the availability of the window. The next two keywords control the window attributes.


The GETATR (Get Attribute) and SETATR (Set Attribute) keywords set a host of attributes for parts. The keywords can control whether a part is visible or not, such as a timer. You can use them to set colors for borders and backgrounds. And in case there is any doubt, you can retrieve existing attributes from one part through GETATR to set the attributes of another part with SETATR. You can even store the retrieved attributes in variables within the program for any number of uses. These two op codes are most commonly used to set property attributes for windows or other parts. The property UserData is a VARPG-defined field that allows the programmer to pass values back and forth between parts and programs.

In my opinion, the READS (Read Selected) op code alone is almost worth the cost of VARPG. This op code is similar to READC (Read Changed) in RPG, but is GUI-charged. READS not only reads a selected subfile record regardless of any changes but also, in a subfile that has multiple selected records (which can be done quite easily in the GUI world), deselects the already selected record. This may sound simple, but consider what you’d have to do in the green-screen world: check the relative record number, clear the selection field, repaint the screen, etc. This op code prevents most of that hassle.

So, when I learned that a subfile is an object in VARPG, I was ecstatic. I didn’t have to worry about multiple display file management. You drag the subfile object off the parts palette, drop it on your development window, and associate fields with the subfile, and the following user-written code will write all the records to your subfile:

*BLANKS setll myrec

read myrec 80

dow *in80=*off

write mysubfile

read myrec 80


And yes, it’s just that simple! You now have a subfile with all the records from the file loaded. Because you dragged a subfile part to the development window, you set object properties to allow paging, colors, multi-selection of records, etc.

The code in Figure 2 processes records selected in the subfile. The first line denotes the name of the action subroutine RtvRec and specifies that the initiating action is pressing a key within the MyWindow environment. READS is a catchall for all the records that have been selected in the subfile. Within VARPG, a subfile can be defined as a multiple-select subfile, which means that multiple records can be selected and thus processed by READS. The %SETATR line assigns the value GET to the UserData property of the WinMsg window. SHOWWIN simply allows the target window, in this case WinMsg, to be active on the screen. Note that although the window is made active, the window is not necessarily visible. Among the window properties that you can set is a Boolean property called Visible that controls whether the window is available for view.

Make It a Smooth Transition

My final program consisted of a handful of routines, none of which were over 20 lines. For this crude application, development time from scratch took about an hour, if that. I can’t say I’d be able to do that from scratch with RPG IV and DDS.

And I may sound as if I am an advocate of VARPG over other visually related products; I am not. This product worked for me. Amalgamated Software of North America


(ASNA) has a product called ASNA Visual RPG that it touts as being better than VARPG because it is not tied down to the AS/400.

Hopefully, this brief example of the power of VARPG gives an indication of how easy it is to move from RPG IV to VARPG, thereby becoming a GUI programmer without losing any key skills you gained as an RPG IV programmer.

Field Length Dec Type Key? Description

IDNO 6 0 Packed Yes Client ID NAME 25 Alpha No Name PHONE 13 0 Packed No Contact# STATUS 1 Alpha No Status A=Active

Figure 1: In the example project, the records in this file are read and placed in a scrolling subfile.

RtvRec BegAct Press MyWindow

Reads subfil1 80

Dow *in80 = *off

Eval %setatr('winSF':'MyWdw':UserData) = 'GET'

Reads subfil1 80

[[ 03GoldsbyFig2b.txt : 4626 in 03GoldsbyFig2b.txt ]]nddo


Figure 2: Processing selected subfile records is easy for RPG programmers.



Support MC Press Online

$0.00 Raised:

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: