13
Wed, Nov
5 New Articles

The Disk Usage Utility

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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. 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: