27
Sat, Apr
1 New Articles

Slicing and Dicing RTVDIRINF Output

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

Ever wish you had an easy way to query the attributes of the objects in your integrated file system to find, for example, who owns the largest objects in a subtree? Or maybe you wanted to find all the objects in an authorization list regardless of what file system they were in? This article will explain how to build such queries in a few short steps.

In V5R3, IBM added the Retrieve Directory Information (RTVDIRINF) command to collect attributes about objects in a subtree (which can include the entire system) and put them in database files. A corresponding Print Directory Information (PRTDIRINF) command is also provided to print selected subsets of the data collected. The PRTDIRINF command can generate reports based on directories, objects, or owners. Within each type of report, data can be subsetted and sorted.

The question "who owns the largest objects in a subtree?" can be answered by the command PRTDIRINF RPTTYPE(*OBJ). In many cases, the information available in the PRTDIRINF reports will fit your needs. Sometimes, however, you will want to go beyond what is available with the PRTDIRINF command. Although RTVDITINF collects over 80 fields for the full set of attributes, PRTDIRINF will report information from less than 20 of them.

This article discusses ways to customize queries using the data collected by the RTVDIRINF command. First, some additional information about the files created by RTVDIRINF must be understood.

The results of the RTVDIRINF command use Unicode for the character fields because the "root" (/) file system uses Unicode names. The job running the commands needs to have a valid CCSID. A CCSID of 65535, which is the default, indicates that no character set translation is done. A CCSID of 65535 will cause both an error message on the RTVDIRINF and PRTDIRINF commands and unreadable displays on queries. A CCSID of 37 will work in most cases. For interactive use, simply use CHGJOB CCSID(37) before starting.

By default, RTVDIRINF produces the files QUSRSYS/QAEZDxxxxO (for all objects) and QUSRSYS/QAEZDxxxxD (for directories). The QAEZDxxxxO file contains a row for each object in the requested subtree. The QAEZDxxxxD file contains the full path name for each directory in the subtree. Each run produces a new file, which is given a sequentially numbered name (represented by xxxx). Thus, there is a maximum of 9,999 result files possible in any one library. You can also specify your own prefix and library if you like. If you specify your own prefix, only the D and O suffixes are appended. There is no automatic sequence generation. This option is used for some of this article's examples.

Information about specific data fields in these files can be found in the iSeries Information Center under Files and file systems -> Integrated file system -> Access the Integrated File System -> Access using CL commands -> Work with output of the RTVDIRINF and PRTDIRINF commands.

The RTVDIRINF command can be long running if a large subtree (for example, "root") is processed. In that case, you may want to run it as a batch job where is the subtree to process and xxx is an appropriate CCSID:

SBMJOB CMD(RTVDIRINF DIR('')) [CCSID(xxx)]

Just a few more considerations before we get to the fun part:

  • Symbolic links are treated as simple objects; they are not used for path name resolution.
  • File systems on remote systems are not processed.
  • A user-defined file system (UDFS) must be mounted to be processed. This means that references to a UDFS such as /dev/qaspxx/yyy.udfs will only give information on the block special file that represents the UDFS.
  • The files created by RTVDIRINF are just a snapshot of the objects at the time the command was run.

A directory /example, with two subdirectories, was created for the following examples. The results were put into files with a prefix of EXAMPLE in the EXAMPLIB library. The following command was used:

RTVDIRINF DIR('/example') INFFILEPFX(EXAMPLE) INFLIB(EXAMPLIB) 

The command issues a message indicating where the results were placed (very handy if you are using the default naming).

Database files EXAMPLEO and EXAMPLED created in library EXAMPLIB. 
Directory information was successfully retrieved. 

Files were also created over the entire system with a batch job as follows:

SBMJOB CMD(RTVDIRINF DIR('/')) CCSID(37)

The resulting files, QAEZD0009O and QAEZD0009D, were created in QUSRSYS.

Now let's do some examples. We'll start simple and then build to more complex queries. Start Query (STRQRY) examples are first followed by SQL under iSeries Navigator. You may want to follow along by running a RTVDIRINF on a small subtree and substituting your own file and library names in the examples.

STRQRY Examples

These examples will use interactive query via the Start Query (STRQRY) command. Some of the screens are omitted to save space, but the text should allow you to fill in the missing steps.

First, ensure the interactive session has a valid CCSID as described earlier. Then issue the STRQRY command. At the first screen, select 1 (Work with queries) and press Enter. At the next screen, enter 1 (Create) for the option and a name for the query (for example, DEMO1) and press Enter. At this point, you should see the main query definition screen (Figure 1).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080600.png

Figure 1: This is the main query definition screen. (Click images to enlarge.)

Example 1: Simple Selection, Name and Attributes

The first example will display the full name, type, size, and owner of the objects in the /example directory.

Select the Specify file selections option to define the files to use. To get both path and object information, we will do a join on the directory and object files. The directory file is first because it has fewer fields and records. This makes for less paging on later screens to find field names.

Specify the directory file first (EXAMPLED), and then press F9 to prompt for a second file--in this case, the object file (EXAMPLEO). After pressing Enter, the screen should be similar to Figure 2. (Ignore the warning that the files contain DBCS data or text. We took care of potential problems by setting a valid CCSID.)

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080601.png

Figure 2: Select the files.

After pressing Enter to confirm, you will get to a Specify Type of Join screen (not shown). Take option 1 (Matched records) and press Enter. This will take you to the Specify How to Join Files screen (Figure 3).

The files have a common field, which is the directory index. Each directory path in the directory file has a unique index value assigned. Each object record will have a corresponding index value to indicate the path to the object. Remember, from the file selection screen above, the directory file has an ID of T01 and the object file has an ID of T02. Specify the match field as QEZDIRIDX, with a test type of equal (EQ).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080602.png

Figure 3: This is the join fields selection.

Press Enter to return to the main query definition screen.

The path name field (QEZDIRNAM1) is defined as a 1024-character field, and the object name field (QEZOBJNAM) is defined as 512 characters. To make the output display more manageable, redefine them to smaller sizes that will fit the data available. Also, give the result fields shorter, more meaningful names. From the main selection screen, choose Define result fields and redefine the fields (Figure 4). Then press Enter.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080603.png

Figure 4: Remap Name field sizes.

From the main query definition menu, choose Select and sequence fields and select the following fields in ascending order: the PATH and OBJNAME fields that were just defined, T02.QEZOBJTYPE (object type), T02.QEZDTASIZE (object data size), and T02.QEZOWN (object owner). The T02.QEZOWN field is on the second page. After pressing Enter, the screen should look like Figure 5.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080604.png

Figure 5: Select and order the output fields.

At this point, press F5 to see the selected output (Figure 6).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080605.png

Figure 6: This is the output report for example 1.

Notice that the symbolic link shows up as a simple object. The data size is the size of the path name specified in the symbolic link.

Example 2: Adding Summary Information

Now let's take advantage of some of the other query facilities to make the report more interesting. Let's group by object type, sort by size, and generate summary information.

Press Enter to get back to the main definition screen, and then select Select sort fields. Select the object type and size fields for sorting (Figure 7). Give the type field a higher sort priority, because it will be used later for grouping the results. Choose descending (D) for the size field so that the largest objects will show up first.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080606.png

Figure 7: Sort by object type and size.

To check the result of the sort selection, press F5. As a query is built, you can press F5 to see the progress.

After returning to the main query screen, choose Select report summary functions to define the summary information to generate. The number of each object type will be counted, and sizes of each object type will be totaled (Figure 8).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080607.png

Figure 8: Specify object type and size summary information.

Next, go to the Define report breaks option to group by type. Here is where grouping on the object type is done by placing 1 for the break level (Figure 9). After pressing Enter, the Format Report Break screen for break level 0 will appear (not shown in figures), take the defaults by pressing Enter.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080608.png

Figure 9: Grouping on the object type.

Next, the Format Report Break screen for break level 1 will appear. This is where the text for each group of object types is entered. Fill in the text (Figure 10). The &T02.QEZOBJTYPE value indicates that the current value of the object type field should be output on the line.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080609.png

Figure 10: Specify the object type summary text.

Press F5 again to see the final report (Figures 11 and 12).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080610.png

Figure 11: This is final output page 1.

The output is grouped by type, and each group has summary information.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080611.png

Figure 12: This is final output page 2.

Figure 12 shows the final totals for all the groups. This is the break level 0 output from the defaults for that level.

Example 3: Record Selection

In the previous examples, all the records in the object file were used. STRQRY can subset the records to look at just a portion of the data. For this example, the RTVDIRINF on the "root" (/) file system, which generated several thousand records, will be subsetted.

The purpose of this example is to select the records for objects that are in a particular authorization list and display their information. First, select the files and remap the path and object names, as described in the first example. Then, select the QEZAUTLST field, which contains the authorization list that the object is in, the PATH and OBJECT from the remap, and the QEZOBJTYPE fields (as previously described).

Next, select the Select records option from the main query menu and select the records that have QEZAUTLST equal (EQ) to MRFAUTL (Figure 13).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080612.png

Figure 13: Select records for the specified authorization list.

Press F5 to get the results (Figure 14).

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080613.png

Figure 14: Here is the selected record output.

This example was chosen to show that data from multiple file systems is available when the entire system is selected. The first two objects are in folders, the next three are in a library, and the last two are in the "root" (/) file system.

SQL Examples Using iSeries Navigator

After starting iSeries Navigator, select Databases, and then the database name (usually the same as the system name). Under Database tasks, select Run an SQL script to get the SQL script screen.

Example 4: Record Selection Using SQL

This example is similar to the STRQRY authorization list in example 3, but in this case, some SQL features are used. First, we drop the file identifiers (T01 and T02, in the STRQRY examples) when not needed. As long as a field name is unique, only the name is required. The QEZDIRIDX field is the only field name that is common to both files. Second, instead of specifying the join as part of the file specification in the FROM clause, we can do it implicitly as part of the selection in the WHERE clause.

SELECT QEZDIRNAM1, QEZOBJNAM, QEZOBJTYPE

FROM QUSRSYS.QAEZD0009O AS O, QUSRSYS.QAEZD0009D AS D

WHERE QEZAUTLST = 'MRFAUTL' AND

O.QEZDIRIDX = D.QEZDIRIDX

The FROM clause is equivalent to the Specify file selections screens. AS O and AS D serve as short identifiers for the files, which is similar to T01 and T02 in the query. The SELECT clause is the equivalent of the Select and sequence fields in the query. For iSeries Navigator, we don't need to redefine the character field sizes; simply resize the fields by clicking and dragging the column heading separators once the information is displayed.

Press Ctrl+R to execute the SQL statement. The results are shown in Figure 15.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080614.png

Figure 15: The record selection and implicit join.

SQL can also be used interactively with the Start SQL Interactive Session (STRSQL) CL command. In that case, the statement would need to be modified slightly. First, the file name format is different and uses a slash (/) instead of a period (.) to separate the library and file names. Second, it suffers the same problem as query with large character fields. The CAST operator is the SQL equivalent of the varchar() operator of Define result fields in Query. The STRSQL statement would look like this:

SELECT CAST(QEZDIRNAM1 AS CHAR(30)) AS PATH,
CAST(QEZOBJNAM AS CHAR(20)) AS OBJNAME, QEZOBJTYPE

FROM QUSRSYS/QAEZD0009O AS O, QUSRSYS/QAEZD0009D AS D

WHERE QEZAUTLST = 'MRFAUTL'  AND

O.QEZDIRIDX = D.QEZDIRIDX

Example 5: Summary Information

In this example, some of the SQL aggregation functions are used to get summary details for all the object types on the system. In this case, only the object file is used, since the full path name information is not needed.

The SELECT clause specifies the object type field and then performs various summary operations on the type and size fields. The results are grouped by type and then finally sorted by type.

SELECT QEZOBJTYPE AS TYPE,COUNT(QEZOBJTYPE) AS COUNT,MAX(QEZDTASIZE) 
AS LARGEST,SUM(QEZDTASIZE) AS TOTAL 
FROM QUSRSYS.QAEZD0009O 
GROUP BY QEZOBJTYPE 
ORDER BY QEZOBJTYPE

The partial result is shown in Figure 16.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080615.png

Figure 16: Here is summary information on all objects.

Example 6: Subset of Summary Information

Now let's take the result from the previous example and select specific object types for the output. The WHERE . . . IN . . . clause can be used to select only those values that are in a list.

SELECT QEZOBJTYPE AS TYPE,COUNT(QEZOBJTYPE) AS COUNT,MAX(QEZDTASIZE) 

AS LARGEST,SUM(QEZDTASIZE) AS TOTAL 

FROM QUSRSYS.QAEZD0009O WHERE QEZOBJTYPE IN ('*BLKSF','*CHRSF','*DIR',

 '*FIFO', '*STMF', '*SOCKET')

GROUP BY QEZOBJTYPE 

ORDER BY QEZOBJTYPE

The result is shown in Figure 17.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080616.png

Figure 17: This is the subset of summary information.

Example 7: Subset on Calculated Data

This example computes the number of days since a file was last changed, and displays that value for each object. The SQL statement is as follows:

SELECT QEZDIRNAM1, QEZOBJNAM, DATE(QEZCHGTIMA) AS DATE, 
DAYS(CURRENT_DATE)-DAYS(QEZCHGTIMA) AS DIFFERENCE, QEZDTASIZE
FROM EXMPLIB.EXAMPLED AS D                    
INNER JOIN EXMPLIB.EXAMPLEO AS O ON D.QEZDIRIDX = O.QEZDIRIDX    

Here the join is explicitly specified on the FROM clause (just for a little variety). The QEZCHGTIMA field is the time stamp of the last modification. The DATE( ) function will extract the date part of the time stamp. The DAYS( ) function will return the number of days since a system-defined date. Since only the difference is needed, the value of the system-defined date is immaterial.

CURRENT_DATE is an SQL special register that returns the time stamp for the current date. The result is shown in Figure 18.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080617.png

Figure 18: This is the result with calculated data.

The result can be useful as is for small sets of data. For larger result sets, it may be difficult to find the objects that meet the criteria.

To limit the result to the objects that haven't changed in 30 days, add a WHERE clause to select on the date difference. Note the WHERE clause added to the end of the previous SQL statement.

SELECT QEZDIRNAM1, QEZOBJNAM, DATE(QEZCHGTIMA) AS DATE, 
DAYS(CURRENT_DATE)-DAYS(QEZCHGTIMA) AS DIFFERENCE, QEZDTASIZE 
FROM EXMPLIB.EXAMPLED AS D 
INNER JOIN EXMPLIB.EXAMPLEO AS O ON D.QEZDIRIDX = O.QEZDIRIDX    
WHERE DAYS(CURRENT_DATE)-DAYS(QEZCHGTIMA) > 30

The result is shown in Figure 19.

http://www.mcpressonline.com/articles/images/2002/mcart%20v5--03080618.png

Figure 19: This is the selection on calculated data.

Here, only the records of interest are shown. The WHERE clause can be modified to use other selection criteria, such as a particular date or a range of dates.

An alternative to the WHERE clause selection would be to use an ORDER BY DIFFERENCE clause to organize the results in order. This would also allow data of interest to be found easily. Of course, both could be used to select and sort the data.

Create Your Own Queries

The RTVDIRINF command provides a wealth of information about Integrated File System objects. Using Query and SQL, the data can be subsetted and organized into more meaningful forms. This article has shown only a few examples of the possibilities. With the power of Query and SQL and the field definitions for the RTVDIRINF files, you can extract and organize the information that is of interest to you.

Important Update Information

In V5R3M0, there is incorrect information stored for some fields. Users of V5R3M0 should apply PTF SI20628. This PTF can be immediately applied.  The RTVDIRINF command should be re-run after the PTF is applied so that the correct data is stored. See the PTF for more information. This problem is fixed in base release V5R4M0.

In V5R4M0, the CCID on the RTVDIRINF command is set to 37 if the default job CCSID is 65535. The command will then have a valid CCSID, and an error message is not signaled.

Dennis DeLorme is an iSeries developer on the Integrated File System team at IBM Rochester. He can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: