|
|
![]() |
|
|
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!
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 FormLet'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:
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:
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 CodeNext, 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 FunThis 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!
|
Editors
Contact the Editors |
|
Last Updated: 6/6/02 Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |