In the April 2000 issue of Midrange Computing, I wrote an article, entitled “HTML: The New 5250,” in which I showed how HTTP mirrored the 5250 protocol and suggested that HTML could become the new 5250. In that article, I focused on the endpoint of that transition—a JavaServer Page (JSP) that emulates a subfile—but glossed over the details. Well, I’m now going to explain the steps required to get from green to graphical.
Architecture
Emulating a subfile in HTML is another example of the revitalization architecture that I introduced in previous articles. The idea is to replace I/O operations in the original, monolithic RPG program with calls to an API. The API then forwards the requests to an object that emulates a display file (a display file proxy), and, finally, a user interface retrieves the data from the proxy and presents it to the user.
Figure 1 shows the original 5250 protocol. The application program communicates with the device description, which, in turn, exchanges data with the 5250 device. In Figure 2, an intelligent client sits on the workstation and communicates with the display file proxy. This “thick” client has full GUI capabilities and, if written in Java, can be easily ported to any workstation. The primary disadvantage is that an application-specific piece of code must reside on the workstation. Figure 3 (page 84) shows the thin-client option, which uses HTML as the communication vehicle. Any browser can be used on the client, and no application-specific code needs to be kept up to date. The downside is that the interface is limited to HTML, but an HTML-only interface is perfectly capable of supporting subfile emulation.
In both graphical solutions, the client/server APIs communicate with the display file proxy object, so the application client is identical for the two approaches. I’m going to focus on the thin-client solution using the WebSphere Application Server, servlets, and JSPs.
The Logic of Subfiles
To do this, I need first to examine how to program subfiles. There are several different programming techniques, but this article deals with the simplest one, the “fully loaded” subfile. To load and display this type of subfile, follow these steps:
1. Clear the subfile with a WRITE to the subfile control record that has SFLCLR enabled.
2. Loop through your data, writing to the subfile one record at a time.
3. Display the data using an EXFMT to the subfile control record.
Figure 4 shows the data flow of the output cycle. Once the user finishes entering data and presses a command key, the application program reads the data from the subfile using either CHAIN or READC.
The HTML Table
Figures 5 and 6 show an example of the source and output of a simple two-row table with headings. HTML tables are dynamically created from tags. A table consists of a table definition, which consists of row definitions, which, in turn, contain either column headings or data elements. There are many other parameters to a table, and you should use one of the many HTML editing tools to actually create and format the appearance of your table. The tool creates the tags; all you have to do then is fill in the data between the tags.
You may have noticed that the table has only output fields. To make the first cell in the first row input-capable, you replace the data in the first cell with the following HTML input field definition:
Doing this gives you the table shown in Figure 7. Other issues arise when you start talking about input fields. For example, you have to create a form, which associates the input fields with buttons on a Web page. That is outside the scope of this article but is covered in detail in the many excellent HTML books available. You can also learn about creating forms by visiting the World Wide Web Consortium’s Web site at www.w3c.org
.
The JSP Implementation
Finally, you have to get the data from the proxy into the table. The cleanest way to do this is to use a JSP. A JSP is, in essence, a “fill in the blanks” HTML document; the “blanks” are “filled in” by calls to a JavaBean. In the JSP/servlet architecture, the bean is populated by the servlet and passed as a parameter to the JSP. When emulating a subfile, the display file proxy is the JavaBean; it contains all the data that would normally be written to the subfile.
A bit of finesse is needed to define the table. You know the layout of a single row, but you don’t know exactly how many rows are to be displayed. This is where the second feature of JSP, scripting, comes into play. Using “scriptlets,” you code a Java loop right into the HTML that will execute each row. Your display file proxy bean then needs just a couple of methods: one that gets the next row and another that returns the contents of a field in the current row.
Figure 8 shows code that would replace the two hardcoded rows of Figure 4. The getField method must be smart enough to return an HTML input field definition for an input-capable field. The servlet retrieves the data from the fields and updates the subfile when the user submits the page.
Execute Code Reformat
What you’ve just read is a step-by-step process for moving a green-screen subfile to an HTML display with very little change to the original application program. The original program replaces I/O op codes with API calls, and the servlet and display file proxy handle the bulk of the conversation from that point on. Only when an EXFMT op code is emulated does HTML (or, more precisely, the JSP) come into play, and, as you’ve seen, the JSP
coding is really not very difficult. Visit www.java400.net/MC/MC200007index.htm for a complete, working example of an emulated subfile.
Application Program Application Client
AS/400 5250 Device
XXXXXX XXXX XXX XXXX XXX
5250
DEVD Client/
Server APIs
Figure 1: The original 5250 protocol featured a character-mode dumb terminal connected via twinax cabling.
AS/400 Workstation
“Thick Client” UI Server
Display File Proxy
Figure 2: In a typical thick-client solution, business logic resides on a powerful PC, and relational data resides on a host system.
AS/400
WebSphere JavaServer Page
Display File Proxy
Servlet
Workstation
Application Client Client/
Server APIs
xxxx xxxx xxxx
Web Browser
Figure 3: With a thin-client, or browser-based, solution, business logic remains on the host system.
1. WRITE Control (SFLCLR)
3. EXFMT Control
2. Loop WRITE Subfile
XXXXXX XXXX XXX XXXX XXX
Figure 4: The logic required to populate a fully loaded subfile can be done in three basic steps.
Column 1 Heading | Column 2 Heading |
---|---|
Row 1, Column 1 Data | Row 1, Column 2 Data |
Row 2, Column 1 Data | Row 2, Column 2 Data |
Figure 5: The new user interface is HTML, and HTML tables effectively replace subfiles.
Figure 6: Even the most basic HTML tables present rows and columns of data with a little more pizzazz than could be mustered with a 5250 subfile.
Figure 7: The cells of HTML tables can be input-capable.
Figure 8: A JSP view bean, such as jdspf, can be used to pull values from rows of a subfile constructed from an RPG application server.
LATEST COMMENTS
MC Press Online