Stuff
OS/400 Edition
Volume 1, Number 11 -- June 6, 2002

VARPG Subfiles: An Introduction


by Shannon O'Donnell

In "VARPG and iSeries Databases," I show you how easy it is to interact with an iSeries database. In this article, I'm going to use that same database to demonstrate just how easy it is to use subfiles in VisualAge for RPG. In fact, you're going to discover that coding subfiles in VARPG is even easier than coding them in the traditional green-screen environment!

display

If you haven't already done so, read the other VARPG article in this issue. We'll use the database you created in that article to populate our subfile in this article. If you have already created that database, add 10 or 20 records to it, so we can have some data to display in our subfile demo here.

Setting Up the VARPG Form

Let's start by creating a new VARPG project. If you're unsure about how to do this, be sure to check out the previous VARPG articles in Midrange Programmer, OS/400 Edition. Here are the steps you need to take to design our subfile form.

Add one subfile part to the form and one push button part. Set the part properties as follows:

  • Window: Part Name = "WIN1"; Title = "Subfile Example"

  • Subfile Part: Part Name="SUB1"

From the Subfile Part Properties panel, click the tab labeled Field list. This is where we'll add our subfile fields to the display.



What we'll do here, in the interest of keeping everything simple, is add the field names that have already been defined in our sample database on the iSeries. Click the Add Before button and add the following subfile fields. Be sure to set their properties as follows:

  • Column Name: "IITEM", Heading Alignment="CENTER", Data Alignment="CENTER" , Column Width="70", Type="Character", Length="7"

  • Column Name: "IQTY", Heading Alignment="CENTER", Data Alignment="CENTER" , Column Width="100", Type="Numeric", Length="5, 0"

  • Column Name: "IPRICE", Heading Alignment="CENTER", Data Alignment="CENTER" , Column Width="100", Type="Numeric", Length="7, 2"

  • Column Name: "IDESC", Heading Alignment="CENTER", Data Alignment="CENTER" , Column Width="200", Type="Character", Length="50"

You can set the column headings for each of these fields to something appropriate for the particular field's contents.

Note also that, since we're using the fields directly from the remote database, we could have used the Reference property to do a field reference directly from the database, rather than defining each field individually. You can use either method you like to define the fields.

The last thing you need to do to define your form is to define the push button. Set your push button's properties as follows:

Push Button: Part Name = "PSBEXIT", Label = "Exit"

Adding the Code

Next, we need to define an AS/400 server for this project. This will tell the compiler where to look for the database descriptions of the remote file. To define the server, click the Server menu item, and then click the Define AS/400 Information menu item. You'll need to add a reference here to your AS/400.

Note: If you have not yet set up the Communications Console, you'll need to do so before you can define a server reference. If you're not sure how to accomplish this, check out "Introduction to Communications Console and CODE/400's Code Editor."

The next step is to add an F-spec to your VARPG source code that describes the remote file. To access the source, click the VARPG Edit Source toolbar button. (It looks like a piece of paper with a pencil on it. It's the fifth one in from the left. If you're still not sure which one it is, move your mouse over each toolbar button and let it hover so that you can see the description of the buttons.)

Add the following line of code to your VARPG source program:

FItemMastP1IF   E           K DISK    REMOTE

Notice that the F-spec is exactly the same as it would be on a local iSeries. The only difference is the use of the keyword REMOTE. This tells the compiler, and the compiled object, that the file can be found on a remote server. (Now you know why you had to define that remote server in the previous step!)

Now let's add the logic that makes all of this work.

Add a PRESS Event to the Exit push button part. Set on the Last Record Indicator when the user presses this button.

Add a CREATE Event to the Subfile Part. This event will be fired every time the program first opens. This is where we'll add the code to actually load the subfile. And this is where you'll see just how easy it really is to use subfiles in VARPG! Add the following code to this part's CREATE event:

C     SUB1          BEGACT    CREATE        WIN1
  *
  * Read the physical file on the iSeries
 C                       Read      ItemMastP1                99
 C                       Dow       *In99 = *Off

  * Write the Subfile record
 C                      Write     Sub1
  *
 C                     Read      ItemMastP1                  99
 C                     Enddo
 C
  *
 C                    ENDACT

As you can see, all this code does is read the physical file on the host and then issue a write to the subfile part. That's it. The whole enchilada. That's all you need to create the subfile. Pretty nifty, huh? Since we made the field names in the subfile the same as the field names in the iSeries database, we don't even have to worry about doing any moves. The data is automatically loaded into the subfile fields every time this program initiates. Clearing, initializing, and relative record number counting is all taken care of for you behind the scenes. What could be easier?

Save and compile the program and give it a whirl. It should something like the one shown here:




Have Fun

This was an example of a very simple VARPG subfile. Of course, you can get into much more complexity with VARPG subfiles. And you'll probably need to explore these complexities, such as using the page up, page down, and column numbers properties, in order to make your subfiles truly useful. Those topics are all relatively complex, so we'll have to explore them in another article. For now, experiment on your own and see what you come up with. One thing you'll quickly discover is that VARPG subfiles are a whole lot more fun than their green-screen counterparts!




Sponsored By
PROFOUND LOGIC SOFTWARE

Looking to increase programmer productivity? Visit http://www.RPGAlive.com/now.

RPG-Alive adds an array of graphical features to IBM's native Source Edit Utility, and is one of only a few products to receive a 10 out of 10 rating in an independent evaluation by 400Times.

RPG-Alive allows RPG programmers to quickly gain an understanding of existing RPG programs, and facilitates a quicker way for programmers to change or write new source code.

Here is what RPG-Alive users say:

Name: Glenn Elliott
Company: GDX Automotive
"Your software is awesome. If someone were to sit down and figure out a great software program to accent code generation on a 400, this would be it. Everything from source code indentation to promptable key words. What a time saver! Thank you for saving me some time!"

Name: Stuart Rowe
Company: Help/Systems, Inc.
"Installation went flawlessly, it started working without asking any questions, no lengthy setup, keep it up you're doing a great job. I have my manager poised over the checkbook with pen in hand as I type this."

Name: Krish Thirumalai
Company: Manhattan Associates
"Excellent product. We have a lot of people in our organization that use and love this product. The built-in help for opcodes and BIF's is really cool! Our programmers no longer need to search for their RPG manuals to look up these opcodes."

Name: Jim Kucharik
Company: Victaulic Company of America
"Your product has won the hearts of our programmers, not an easy thing to do!"

To try RPG-Alive on your system, visit http://www.RPGAlive.com/now or call (937) 439-7925.



THIS ISSUE
SPONSORED BY:

Aldon Computer Group
Client Server Dev.
Affirmative Computer
ASNA
Profound Logic Software
WorksRight Software


BACK ISSUES

TABLE OF CONTENTS
How Do I Set My CLASSPATH? Let Me Count the Ways

VARPG and iSeries Databases

Create WAR Files with Sun's Free DeployTool

Qshell Pattern Matching

VARPG Subfiles: An Introduction

iSeries Toolbox for Java: Running an iSeries Command

Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Richard Shaler

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com



Last Updated: 6/6/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.