My previous articles on CGIDEV2 ("Getting Started with CGIDEV2 – Part 1" and "Getting started with CGIDEV2 -- Part II"), I discussed how to write a program using CGIDEV2 to produce a simple report for the Web and how to write a "paging" report. I also introduced the basic format of an HTML form. In this article, it is time to look at how you can write a simple subfile program and a maintenance program.
Figure 1 shows an example of a "Load All" style subfile Web page. The user can add a new product by keying in the new product code and clicking the Add button. Alternatively, he can update or delete an existing product by simply clicking on the product code.
[TABLE]Figure 1: A "Load All" style subfile Web page
Figure 2 shows the Web page displayed when the user opts to add a new product. The user enters the values and clicks the Add button to add the product.
[TABLE]Figure 2: Adding a new product
Figure 3 shows the Web page displayed when the user selects an existing product. The user makes the required changes and clicks either the Change or Delete button.
For both add and change, the category code is selected from a drop down box; whereas the user selects a category description it is actually the category code that is returned to the program. This is the HTML equivalent of an F4 prompt where the list of available options is of a manageable size.
Also note how the picture of the product is displayed.
[TABLE]Figure 3: Maintaining an existing product
The subfile page
Figure 4 shows the HTML for the subfile page. In the tablestart section the definition of the form addCode allows for the entry of a new product code by issuing a call to CVALL002B when the Add button is selected. Each product code listed in the table (tableline section) has a hyperlink to call CVALL002B with the product code as a parameter.
Figure 4: HTML f
To continue reading for free, register below or login
To read more you must become a member of Search400.com
');
// -->

or "Load All" style subfile
Are you ready for the complicated subfile program? Figure 5 shows the source of the CGIDEV2 program CVALL002A. Your eyes do not deceive you; that is all there is. The program bears a striking resemblance to the original report program in that it simply lists all of the products. The enormous benefit of using HTML is that the program does not need to process the subfile because any actions are initiated directly from the HTML (i.e. all calls to CVALL002B are initiated from the HTML).
Figure 5: The subfile program
The maintenance program
Before we look at the maintenance program, I just want to point out that this is just one of many ways of providing a maintenance function. In this example there is one program that provides for the loading, displaying and validation of the Web page and as well as adds, updates or deletes the record. Another option is to divide this into separate programs for the load/display and the validation/process.
Figure 6 shows the HTML for the maintenance program. The Web page is basically a form that calls the program CVALL002B. The main sections are changebutton and addbutton (towards the end of the page); one of those will be written depending on whether a product is being added or changed. All of the submit buttons have the same name of CGIOption, which is used by the maintenance program to determine if a product is to be added, updated or deleted. Also make a note of the selectoption section, which is used to generate the drop down list for category selection; the lines preceding and following selectoption identify the HTML select name. And then there are the MsgStart, MsgL1 and MsgEnd sections, which are used to display error messages.
Figure 6: HTML for the maintenance program
Figure 7 shows the CGIDEV2 maintenance program CVALL002B. The main points of the mainline are as follows:
Figure 7: The maintenance program
As in previous CGIDEV2 programs, the usual criteria about binding directories, copy members and work fields apply, but the important items to note are as follows:
Figure 8: HTML generated from the CrtTagOpt subprocedure
I think you can safely say that the logic for a maintenance program is not that complicated.
I am sure that you noticed that there is no looping logic in either program. Since there is no persistence between the program and the browser, there is no need for the program to loop: a program receives data, processes it and sends a Web page.
One step further
Now you know the basic principles of how you can use CGIDEV2 to write subfile and maintenance programs. In the next article I will start looking at some of the other strange and wonderful things you can do with CGIDEV2.
---------------------------
About the author: Paul Tuohy is CEO of ComCon, an iSeries consulting company. He is the author of Re-Engineering RPG Legacy Applications and is one of the quoted industry experts in the IBM Redbook "Who Knew You Could Do That With RPG IV?"