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 IBMs 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 youll 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 programsalbeit suitable to some tasksleave 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 customers 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.
BEGACT/ENDACT
Now that Ive 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.
SHOWWIN/CLSWIN
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.
GETATR/SETATR
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 youd 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 didnt 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
enddo
And yes, its 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 cant say Id 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
READS
(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
D=Deceased
I=Inactive
P=Pending
X=Cancelled
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
EndAct
Figure 2: Processing selected subfile records is easy for RPG programmers.
LATEST COMMENTS
MC Press Online