Brief: Here's a client/server utility that graphically shows you the sizes of your AS/400 libraries. Find out how you can use Visual Basic and the Remote SQL APIs to give numerical values a whole new look.
Last month, I explained some of the basic concepts of using PC Support Windows APIs. This month I'll expand on that knowledge by giving you a full-featured client/server utility. I used Microsoft Visual Basic and IBM's PC Support Remote SQL APIs to create the Disk Usage utility which graphs the sizes of your AS/400 libraries. You'll see how this utility taps into the AS/400 database while exploiting the graphics capabilities of today's high-resolution PC displays.
Overview
The Disk Usage utility allows you to create bar graphs or pie charts showing your AS/400 disk usage. The graphs show the amount of disk used by the nine largest libraries on your system. All other libraries are grouped together into a single bar or pie slice. (Later I'll show you how to adjust the number of libraries by changing only a single line of code.)
On the bar graph, the height of each bar represents the amount of disk (in megabytes) used by the specified library. On the pie graph, the size of each slice represents a percentage of the total used disk space, as opposed to the total available disk space. This is an important distinction because the graphs do not show the amount of unused disk space or any of the space used internally by the system. They do, however, give you a way to visually display library sizes, which helps you analyze how disk usage is distributed on your system.
Requirements
Before you can begin using the Disk Usage utility, you need to consider a few requirements.
First, you must be running PC Support for Extended DOS in the Microsoft Windows environment. In V3R1, this translates into either Client Access for Extended DOS in the Windows environment or Client Access for Windows 3.1.
Second, before you run the utility, you must run an Operational Assistant job on the AS/400 to collect the disk space information. The Disk Usage utility uses this information to calculate the library values for the graphs. To collect the disk space information, sign on with a user profile that has all object (*ALLOBJ) authority, security officer (*SECOFR) user class, and is enrolled in the system directory.
Once you have signed on to the AS/400, you can collect disk information in one of two ways. The first way is to enter the GO DISKTASKS command, which presents the Disk Space Tasks menu. Select option 1 (Collect disk space information). You'll be presented with the Collect Disk Space Information screen. Here you have options to collect the disk information at a specific date and time or to schedule the collection on a weekly or monthly basis.
The other way to collect disk space information is to submit the Retrieve Disk Information (RTVDSKINF) command to batch. Once you have collected the disk space information, you're ready to begin using the Disk Usage utility.
Installation
The easiest way to get a copy of the Disk Usage utility is to go to the Files Area of MC-BBS and select the directory for "MC Magazine's Published Files for AS/400." Download the file named DSKUSPKG.EXE. The self-extracting archive file contains the source code and programs for the utility, including a setup program, SETUP.EXE. To install the utility, run SETUP from the Windows Program Manager. This program automatically installs all of the necessary components and creates a Windows program group containing an icon which you can use to run the utility.
If you decide to key in the code for this utility there are additional requirements. First, this utility takes advantage of two Visual Basic Extensions (VBXs), GRAPH and THREED, which are only available in the Professional Edition of Visual Basic. (For more information on VBXs, see "Custom Controls: The Muscle Behind Visual Basic," elsewhere in this issue.) You'll also have to obtain a copy of the PCSMCPY dynamic link library (DLL). You can retrieve this DLL from your AS/400 using the IWSTOOL command in the QIWSTOOL folder.
Using the Utility
When you run the Disk Usage utility, you're presented with the dialog box shown in 1 (page 91). This dialog box asks you whether or not you want to summarize the disk space information. You only need to perform this summarization once each time you run the Operational Assistant job on the AS/400 to collect the disk space information. If you answer Yes, be prepared to wait a few minutes while the utility summarizes the disk space information. If you have already summarized the disk information and have not rerun the collection job, you can select the No button. Selecting No causes the utility to use the data from the last time the information was summarized. The Cancel button allows you to exit the program immediately if you don't want to perform either action.
When you run the Disk Usage utility, you're presented with the dialog box shown in Figure 1 (page 91). This dialog box asks you whether or not you want to summarize the disk space information. You only need to perform this summarization once each time you run the Operational Assistant job on the AS/400 to collect the disk space information. If you answer Yes, be prepared to wait a few minutes while the utility summarizes the disk space information. If you have already summarized the disk information and have not rerun the collection job, you can select the No button. Selecting No causes the utility to use the data from the last time the information was summarized. The Cancel button allows you to exit the program immediately if you don't want to perform either action.
If you didn't select Cancel, you will see status messages at the bottom of the screen. The utility presents these message while it attempts to access information on the AS/400. During this time, the utility performs a number of error checks. If no errors are encountered, the next screen you'll see is the AS/400 Disk Usage screen. This screen shows you a bar graph of your AS/400 libraries similar to the one shown in 2 (page 91).
If you didn't select Cancel, you will see status messages at the bottom of the screen. The utility presents these message while it attempts to access information on the AS/400. During this time, the utility performs a number of error checks. If no errors are encountered, the next screen you'll see is the AS/400 Disk Usage screen. This screen shows you a bar graph of your AS/400 libraries similar to the one shown in Figure 2 (page 91).
The AS/400 Disk Usage screen has several buttons that allow you to perform various tasks. The two Graph Type radio buttons toggle the display between a bar graph and a pie graph. An example of the pie graph is shown in 3. The Print button prints the currently displayed graph on the default printer. The Copy button copies the currently displayed graph to the Windows clipboard so that you can paste it into other Windows applications. The Exit button exits the application.
The AS/400 Disk Usage screen has several buttons that allow you to perform various tasks. The two Graph Type radio buttons toggle the display between a bar graph and a pie graph. An example of the pie graph is shown in Figure 3. The Print button prints the currently displayed graph on the default printer. The Copy button copies the currently displayed graph to the Windows clipboard so that you can paste it into other Windows applications. The Exit button exits the application.
If your PC is attached to multiple AS/400s, PC Support automatically designates one of them as the default system. The Disk Usage utility always uses the default system. If you have more than one AS/400, you can change the default system. To do this, select the AS/400 Connection icon in the PC Support or Client Access program group before you run the Disk Usage utility. You'll see an AS/400 Connection window similar to the one shown in 4. The current default system is shown at the bottom of this window. To change the default system, select a system name from the Connected systems list box and click the Set as default button. When you run the Disk Usage utility, it will access the new default system.
If your PC is attached to multiple AS/400s, PC Support automatically designates one of them as the default system. The Disk Usage utility always uses the default system. If you have more than one AS/400, you can change the default system. To do this, select the AS/400 Connection icon in the PC Support or Client Access program group before you run the Disk Usage utility. You'll see an AS/400 Connection window similar to the one shown in Figure 4. The current default system is shown at the bottom of this window. To change the default system, select a system name from the Connected systems list box and click the Set as default button. When you run the Disk Usage utility, it will access the new default system.
Walk-through
You don't need to understand the Visual Basic code in order to use the Disk Usage utility. At this point you have enough information to begin using it right away. However, if you want to learn more about Visual Basic and the Remote SQL APIs keep reading while I take you on a quick walk-through of the code.
The code for the Disk Usage utility is shown in5 through 13. This code is all part of one file called DISKUSGE.FRM, however I've broken it down into small pieces to facilitate this discussion. 5 shows the properties for the form which are set at design time.
The code for the Disk Usage utility is shown in Figures 5 through 13. This code is all part of one file called DISKUSGE.FRM, however I've broken it down into small pieces to facilitate this discussion. Figure 5 shows the properties for the form which are set at design time.
6 contains the declaration section of the form. The highlighted code shows the declaration for the constant MAXLIBS. This constant is set to 10 to represent the nine libraries shown on the graph plus the bar or slice for all other libraries. By changing this constant, you can easily alter the number of libraries displayed. For example, to show the 19 largest libraries instead of the nine largest libraries, change this value to 20.
Figure 6 contains the declaration section of the form. The highlighted code shows the declaration for the constant MAXLIBS. This constant is set to 10 to represent the nine libraries shown on the graph plus the bar or slice for all other libraries. By changing this constant, you can easily alter the number of libraries displayed. For example, to show the 19 largest libraries instead of the nine largest libraries, change this value to 20.
The program starts executing at the beginning of the Form_Load subroutine shown in 7. Here the program uses a dialog box to ask if you want to summarize the disk space information. If you select the Cancel button, the program executes the cmdExit_Click subroutine which ends the program. If you select the Yes button, the program executes the SumDiskInfo function (label A in 7) where the disk information is summarized. If any errors occur while summarizing the disk information, the function returns a non-zero value and the program ends. If no errors occur while summarizing the disk information or you select the No button, the program executes the GetDiskInfo function (label B in 7) to get the disk information. If any errors occur, this function also returns a non-zero value and the program ends. Finally, the program passes the value "Bar" to the CreateGraph subroutine (label C in 7) which generates the first bar graph.
The program starts executing at the beginning of the Form_Load subroutine shown in Figure 7. Here the program uses a dialog box to ask if you want to summarize the disk space information. If you select the Cancel button, the program executes the cmdExit_Click subroutine which ends the program. If you select the Yes button, the program executes the SumDiskInfo function (label A in Figure 7) where the disk information is summarized. If any errors occur while summarizing the disk information, the function returns a non-zero value and the program ends. If no errors occur while summarizing the disk information or you select the No button, the program executes the GetDiskInfo function (label B in Figure 7) to get the disk information. If any errors occur, this function also returns a non-zero value and the program ends. Finally, the program passes the value "Bar" to the CreateGraph subroutine (label C in Figure 7) which generates the first bar graph.
As you've just seen, there are three main routines which are executed from the Form_Load subroutine (SumDiskInfo, GetDiskInfo, and CreateGraph). I'll describe these routines in more detail.
Processing Details
8 shows the code for the SumDiskInfo function. This subroutine summarizes the collected disk space information. It begins by executing the EHNRQ_Start API (label A in 8) which starts a remote SQL server job on the AS/400.
Figure 8 shows the code for the SumDiskInfo function. This subroutine summarizes the collected disk space information. It begins by executing the EHNRQ_Start API (label A in Figure 8) which starts a remote SQL server job on the AS/400.
At label B in 8, the program executes the EHNRQ_Exec API. This API is used to execute any SQL statement other than a SELECT. In this case, the CREATE TABLE statement is executed to create the DISKSUM file in QGPL. (The DISKSUM file is a summarized version of the collected disk space information.) This file contains two fields (DIOBLI and DIOBSZ) to store library names and sizes.
At label B in Figure 8, the program executes the EHNRQ_Exec API. This API is used to execute any SQL statement other than a SELECT. In this case, the CREATE TABLE statement is executed to create the DISKSUM file in QGPL. (The DISKSUM file is a summarized version of the collected disk space information.) This file contains two fields (DIOBLI and DIOBSZ) to store library names and sizes.
Next, the program executes a GRANT ALL SQL statement to grant authority to *PUBLIC. This ensures that other users will not encounter security violations if they attempt to use this file. Then a DELETE SQL statement is executed to delete all records from the file.
Finally, the program executes an INSERT SQL statement with a subselect (label C in 8) which reads records from the QAEZDISK file (the collected disk space information) and summarizes them into the DISKSUM file.
Finally, the program executes an INSERT SQL statement with a subselect (label C in Figure 8) which reads records from the QAEZDISK file (the collected disk space information) and summarizes them into the DISKSUM file.
9 shows code for the GetDiskInfo function. This function retrieves records from the summary file built by the SumDiskInfo function. The function begins by starting the remote SQL server job on the AS/400 if it's not already started. It then executes the EHNRQ_Select API at label A in 9. This API only executes SQL SELECT statements. In this case, the function selects the library name and size from the DISKSUM file and sorts the records in descending order by library size.
Figure 9 shows code for the GetDiskInfo function. This function retrieves records from the summary file built by the SumDiskInfo function. The function begins by starting the remote SQL server job on the AS/400 if it's not already started. It then executes the EHNRQ_Select API at label A in Figure 9. This API only executes SQL SELECT statements. In this case, the function selects the library name and size from the DISKSUM file and sorts the records in descending order by library size.
At label B in 9, the program performs a do-while loop where it executes the EHNRQ_Getf API to retrieve all of the selected SQL records. The records are loaded into two arrays: one for the library names and one for the library sizes. At label C in 9 the program ends the remote SQL server job on the AS/400.
At label B in Figure 9, the program performs a do-while loop where it executes the EHNRQ_Getf API to retrieve all of the selected SQL records. The records are loaded into two arrays: one for the library names and one for the library sizes. At label C in Figure 9 the program ends the remote SQL server job on the AS/400.
10 shows the CreateGraph subroutine. This subroutine creates either a bar or pie graph depending on the value of the parameter passed to it. The subroutine performs a loop where the values from the two arrays are used to load the data points, labels, and legend for the graph. After that, the subroutine loads the type, style, and title of the graph. Then the subroutine draws the graph on the screen.
Figure 10 shows the CreateGraph subroutine. This subroutine creates either a bar or pie graph depending on the value of the parameter passed to it. The subroutine performs a loop where the values from the two arrays are used to load the data points, labels, and legend for the graph. After that, the subroutine loads the type, style, and title of the graph. Then the subroutine draws the graph on the screen.
11 shows the optBar_Click and optPie_Click subroutines. These subroutines execute when you select the corresponding graph type. Each of the subroutines has one line of code that passes a value ("Bar" or "Pie") to the CreateGraph subroutine which, in turn, creates the appropriate graph.
Figure 11 shows the optBar_Click and optPie_Click subroutines. These subroutines execute when you select the corresponding graph type. Each of the subroutines has one line of code that passes a value ("Bar" or "Pie") to the CreateGraph subroutine which, in turn, creates the appropriate graph.
12 shows the cmdPrint_Click and cmdCopy_Click subroutines. These subroutines execute when you select the corresponding button (either Print or Copy). Each of these subroutines also has only one line of code that either prints the graph or copies it to the clipboard.
Figure 12 shows the cmdPrint_Click and cmdCopy_Click subroutines. These subroutines execute when you select the corresponding button (either Print or Copy). Each of these subroutines also has only one line of code that either prints the graph or copies it to the clipboard.
13 shows the cmdExit_Click subroutine which executes when you select the Exit button. This subroutine ends the application.
Figure 13 shows the cmdExit_Click subroutine which executes when you select the Exit button. This subroutine ends the application.
Run With It
This utility graphs the sizes of selected AS/400 libraries. However, if you have Visual Basic, you could modify the utility to graph other meaningful data on your system. For instance, if you work for a retail company, you might want to graph the last 12 months of sales history for selected items your company sells. This graph could identify seasonal trends and help your company target advertising and promotional opportunities. Ideas like these can generate useful client/server applications for the decision makers at your company. It's up to you to make it happen.
Robin Klima is a senior technical editor for Midrange Computing.
REFERENCES Microsoft Visual Basic Professional Features Book. Microsoft Visual Basic Programmer's Guide. PC Support/400 API Reference (SC41-8254, CD-ROM QBKA6102).
The Disk Usage Utility
Figure 1 Summarize Disk Information Dialog Box
UNABLE TO REPRODUCE GRAPHICS
The Disk Usage Utility
Figure 2 Disk Usage Bar Graph
UNABLE TO REPRODUCE GRAPHICS
The Disk Usage Utility
Figure 3 Disk Usage Pie Graph
UNABLE TO REPRODUCE GRAPHICS
The Disk Usage Utility
Figure 4 AS/400 Connection Window
UNABLE TO REPRODUCE GRAPHICS
The Disk Usage Utility
Figure 5 Figures 5 - 13
All components for this utility are contained in the self-extracting file: DSKUSPKG.EXE This file can be found in the download area of the MC-BBS.
LATEST COMMENTS
MC Press Online