Suppose a user in accounting uses his PC spreadsheet package to produce reports, such as financial statements. This user wants to take information from the AS/400 and move it into a PC spreadsheet to process it or spruce it up for presentation.
Such an operation is a nuisance for the programmer because of the steps involved.
o Convert the data on the AS/400 into a format that is meaningful to the user when it is downloaded to the PC.
o Use PC Support to get the data to the PC by creating a transfer request and downloading the data.
o Once the file is on the PC, import it to a spreadsheet package, like Lotus or Excel, then parse the file (parsing is the process of assigning text data to spreadsheet columns).
o Finally, strip extra baggage like page headings.
While this process is effective, it's too clumsy to perform on an ongoing basis.
The user-driven AS/400 Report Download Utility performs all these steps, freeing programmers and users to spend their time more productively.
The utility is an example of Visual Basic (VB) client/server coding. It is a client/server application that allows PC users to download an AS/400 report into a Microsoft Excel spreadsheet, Microsoft Word document, or PC text file- all from a Windows-based PC.
There are no PC Support transfer requests, file description files (FDFs), or intermediate steps-the PC Support router is a direct conduit. So instead of programmers downloading data to PCs, users can download data themselves by following these simple steps.
o Generate a query on the AS/400 to collect and summarize the data into report form or run an existing AS/400 report. The report is not printed; it's kept in an output queue.
o Call the Report Download Utility from the PC. To display a list of spooled files, enter an output queue name or select one from the list.
o Select and download a spooled file. Once the data is downloaded, the utility also can run a specified macro to do parsing, stripping, formatting, calculating, printing, and anything else the PC program is capable of.
o Without leaving the download utility, select the next file to be downloaded, or simply begin processing the information using the PC application.
The macro is attached to the download process, so the process is automated for the user's future use. The next time the user wants to download the same report, the macro is called again, thereby automating the entire process.
The utility is useful because of its ability to automatically run an Excel or Word macro over the downloaded data. The utility downloads a spooled file to a PC spreadsheet or document and then invokes saved macro instructions to process the data. The macros must be prerecorded and stored in a macro sheet (Excel) or a template (Word) before the utility can execute them.
This utility can be modified to work with other products, such as WordPerfect or Lotus 1-2-3. Programmers who want to modify the VB source code must use Microsoft's Visual Basic.
The Client/Server Platform
The AS/400 Report Download utility is a nuts-and-bolts client/server application. The components are simple and common: a VB program, an RPG program, CL programs, physical files, and an Intersystem Communication Function (ICF) file.
The link from the PC Support router to the RPG partner program is achieved through the ICF file. Support for the functions of ICF files is built into OS/400 and PC Support for Windows.
A standard Advanced Program-to-Program Communications (APPC) relationship, established through the PC Support router, maintains the link between the AS/400 and the PC. Data is then transported over the link.
Some of the data passed back and forth takes the form of messages from one program to the other. The PC program sends requests to the AS/400 program. The AS/400 collects the requested information and sends it back with messages telling the PC the status of the request.
For information on installing this utility, see the accompanying sidebar.
How to Use It
To use this utility, the user starts PC Support and Windows. The utility uses only the PC Support router; it doesn't require any workstation function (WSF) sessions. Once PC Support is started, the user launches the utility the same way he would launch any other Windows application-by double-clicking the icon (see 1). The install process creates a program group and two icons.
To use this utility, the user starts PC Support and Windows. The utility uses only the PC Support router; it doesn't require any workstation function (WSF) sessions. Once PC Support is started, the user launches the utility the same way he would launch any other Windows application-by double-clicking the icon (see Figure 1). The install process creates a program group and two icons.
The utility checks to make sure that the PC Support router is loaded. Next, it checks the standard installation directories for Microsoft Excel and Word. The opening screen for the utility is then presented (see 2).
The utility checks to make sure that the PC Support router is loaded. Next, it checks the standard installation directories for Microsoft Excel and Word. The opening screen for the utility is then presented (see Figure 2).
The user can specify an output queue or click on Browse Outqs to present a list of the output queues to which he's authorized (see 3). Once the user selects an output queue, the screen displays a list of spooled files and the option buttons that represent the features available to process the downloaded report (see 4). Excel and Word options will be visible only if the utility finds them in their standard directories.
The user can specify an output queue or click on Browse Outqs to present a list of the output queues to which he's authorized (see Figure 3). Once the user selects an output queue, the screen displays a list of spooled files and the option buttons that represent the features available to process the downloaded report (see Figure 4). Excel and Word options will be visible only if the utility finds them in their standard directories.
If the user is unsure which spooled file he wants to process, he can preview it as shown in 5. Scrolling through the preview display will reveal the first 150 lines (about three pages) of the file. Report widths of 132 or 198 columns display in correspondingly smaller fonts than 80 column reports. (Any overprinting causes additional lines to be displayed as illustrated by the report title.
If the user is unsure which spooled file he wants to process, he can preview it as shown in Figure 5. Scrolling through the preview display will reveal the first 150 lines (about three pages) of the file. Report widths of 132 or 198 columns display in correspondingly smaller fonts than 80 column reports. (Any overprinting causes additional lines to be displayed as illustrated by the report title.
When the user chooses to download a report to Word or Excel and run a macro, a dialog box comes up (see 6). Selecting the Run macro box prompts the user for the macro name. Word macros are kept in a template (.DOT files), and Excel macros are kept in a macro sheet (.XLM files). The macro must be prerecorded and stored before it can be referenced.
When the user chooses to download a report to Word or Excel and run a macro, a dialog box comes up (see Figure 6). Selecting the Run macro box prompts the user for the macro name. Word macros are kept in a template (.DOT files), and Excel macros are kept in a macro sheet (.XLM files). The macro must be prerecorded and stored before it can be referenced.
When the user chooses to download a report to a PC text file; he is presented with the dialog box shown in 7. This box offers the option to Replace file or to Add to file. With this feature the user can accumulate several AS/400 reports into one file.
When the user chooses to download a report to a PC text file; he is presented with the dialog box shown in Figure 7. This box offers the option to Replace file or to Add to file. With this feature the user can accumulate several AS/400 reports into one file.
Modifications to the Utility
Consider the utility a starting point. It can be modified to do other things, such as interface to other DDE-capable software packages like WordPerfect or Lotus. Programmers can even extract routines from the utility and use them to start new applications. For instance, instead of downloading spooled files, the utility can be modified to download database files. (Indeed, spooled files are copied to database files before they are transmitted.)
Programmers can create bitmap pictures in a utility like Paintbrush and insert them into the utility's forms. For example, the utility's opening form has been enhanced with a personalized logo and 3-D controls (see 8).
Programmers can create bitmap pictures in a utility like Paintbrush and insert them into the utility's forms. For example, the utility's opening form has been enhanced with a personalized logo and 3-D controls (see Figure 8).
How It Works
The AS/400 Report Download Utility is an inclusive and full-function client/server application that ties together several elements of today's application solutions-the AS/400, Windows, PC Support, Microsoft Excel, and Microsoft Word. The help system explains all features of the utility and is accessed from most menus (see 9).
The AS/400 Report Download Utility is an inclusive and full-function client/server application that ties together several elements of today's application solutions-the AS/400, Windows, PC Support, Microsoft Excel, and Microsoft Word. The help system explains all features of the utility and is accessed from most menus (see Figure 9).
The utility is written in VB, and it uses a feature of PC office systems called Dynamic Data Exchange (DDE) to link objects within a VB program to other programs running in Windows. DDE also sends commands to other Windows applications, making functions within Word or Excel available to the VB program.
This VB client/server utility is central to the process of putting all the players together in a cooperative processing solution. This is a role that VB is good at.
Chris Peters is a senior programmer/ analyst for Murphey Favre Securities Service. He can be reached on Compuserve at 76714,1253 or on MC-BBS.
REFERENCES Peters, Chris. AS/400 Client/Server Programming with Visual Basic. Carlsbad, Calif.: Midrange Computing, 1995. Microsoft Corporation. Microsoft Visual Basic Programmer's Guide. Redmond, Wash.: Microsoft Press, 1993. PC Support/400 API Reference (SC41-8254, CD-ROM QBKA6102).
Installing the AS/400 Report Download Utility
Since there are two parts to this client/server utility-the AS/400 part and the PC part-the installation process likewise has two parts. Installation on the AS/400 need be done only once per AS/400; the programs are then available to all users. Installation on the PC must be done on each PC that uses the utility.
You can download a free copy of this utility from MC-BBS. Use a modem to call 619-931-9909. From the Files area, select "MC Magazine's Published Files for AS/400," then download the self-extracting file named RDUPKG.EXE. To extract the utility, copy it into an empty subdirectory on your hard drive and execute RDUPKG from a DOS prompt.
Installing the Utility-AS/400 Code
1. With PC Support running and shared folders active, go to the Windows Program Manager or File Manager. Open the File menu and select Run.
2. Specify the directory containing the expanded files transmitted from MC-BBS.
3. Run the SETUP400 program. (This setup program is a modified version of the VB source code generated by the Application Setup Wizard.) From within the SETUP400 program, the Shell command is used to run a batch file. Since the SETUP400 program can't detect if the batch file runs successfully, the batch file pauses at the end for you to examine the screen messages for errors.
During the installation process, the utility creates an AS/400 library named VBSPL where the AS/400 portion of the utility resides. Because of required hard-coded references to a specific library, you cannot run the utility from any other library without modifying the source code. The utility also creates source files to receive the uploaded AS/400 source code members and uploads them with the PC Support file transfer program RFROMPCB.EXE. Finally, the utility compiles the AS/400 physical files, the ICF file, and the RPG and CL programs.
Source Code for the AS/400
When you download this utility from the MC-BBS, all the source code is included for the elements of the utility. (There's a simple help system, too.) The large amount of code in this utility prohibits us from publishing it in this article.
Installing the AS/400 portion of the Download Utility creates the source files QDDSSRC, QRPGSRC, and QCLSRC in library VBSPL. These source files contain all the AS/400 code for the utility. To help sort things out, a brief description of the AS/400 objects follows. All objects are created in library VBSPL.
ICF File
VBSPLF1 is a standard ICF file for APPC connections. It contains fields for transporting data and messages between the PC and the AS/400.
CL Programs
VBSPLF1C sets the AS/400 environment for the utility (establishes the library list and creates temporary files) and calls VBSPLF1R, the main AS/400 partner program.
CHEKOUTQ checks to see if a requested AS/400 output queue exists.
GETOUTQS loads physical file PQLIST with a list of AS/400 output queues.
GETSPLFS loads physical file PTLIST with a list of AS/400 spooled files for a specific output queue.
GETSPLE loads physical file PDDATA with records from a specific AS/400 spooled file.
RPG
VBSPLF1R program is a standard APPC application communicating through an ICF file. It is the main AS/400 partner program. It handles the APPC conversation with the PC and calls the other AS/400 programs.
Installing the Utility-PC Code 1. The installation program for the PC portion of the code is also a Windows Setup program. Again, open the file menu and select Run. This time, select the program SETUP.EXE.
2. Designate the directory to receive the application; the rest is automatic. This process installs the utility and the Dynamic Link Libraries (DLLs) VBRUN300 and DDEML, and creates two program icons in a new program group.
Running the Utility
To run the utility, PC Support must be running under Windows. The support for the APPC conversation in this client/server relationship comes with OS/400 and PC Support.
This utility requires two Windows fonts-Courier New and Terminal. These nonproportional fonts align properly in subfile-like lists.
Depending on how your AS/400's security is set up, you may have to grant users authority to access the database files in VBSPL that come with the utility- PDDATA, PQLIST, and PTLIST.
Source Code for the PC
A discussion of the VB source code files included in the MC-BBS transmission is beyond the scope of this article. However, all of the utility's VB and client/server code and techniques are explained in AS/400 Client/Server Programming with Visual Basic published by Midrange Computing.
The AS/400 Report Download Utility
Figure 1 Report Download Icon
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 2 Report Download Screen
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 3 Browsing Output Queues
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 4 Displaying Spooled Files
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 5 Previewing a Spooled File
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 6 Loading a Word Macro
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 7 Writing to a Text File
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 8 Personalized Version
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 9 Help Window
UNABLE TO REPRODUCE GRAPHIC
The AS/400 Report Download Utility
Figure 10 RDUPKG.EXE Programs
All components for this utility are contained in the self-extracting file: RDUPKG.EXE This file can be found in the download area of the MC-BBS.
LATEST COMMENTS
MC Press Online