Optimizing File Size: The REBUILD Subcommand

How to:

You use the REBUILD subcommand for one of two reasons. Primarily, you use it to improve data access time and storage efficiency. After many deletions, the physical structure of your data does not match the logical structure. REBUILD REBUILD dumps data into a temporary work space and then reloads it, putting instances back in their proper logical order. A second use of REBUILD REBUILD is to delete segment instances according to a set of screening conditions.

Normally, you use the REBUILD subcommand as a way of maintaining a clean data source. To check if you need to rebuild your data source, enter the ? FILE command (described in Confirming Structural Integrity Using ? FILE and TABLEF):

? FILE filename

If your data source is disorganized, the following message appears:

FILE APPEARS TO NEED THE -REBUILD-UTILITY
REORG PERCENT IS A MEASURE OF FILE DISORGANIZATION
0 PCT IS PERFECT -- 100 PCT IS BAD
REORG PERCENT x%

This message appears whenever the REORG PERCENT measure is more than 30%. The REORG PERCENT measure indicates the degree to which the physical placement of data in the data source differs from its logical, or apparent, placement.

The &FOCDISORG variable can be used immediately after the ? FILE command and also shows the percentage of disorganization in a data source. &FOCDISORG will show a data source percentage of disorganization even if it is below 30% (see the Developing Reporting Applications manual).

Procedure: How to Use the REBUILD Subcommand

The following steps describe how to use the REBUILD subcommand:

  1. Initiate the REBUILD facility by entering:
    REBUILD

    The following options are available:

    1. REBUILD        (Optimize the database structure)
    2. REORG          (Alter the database structure)
    3. INDEX          (Build/modify the database index)
    4. EXTERNAL INDEX (Build/modify an external index database)
    5. CHECK          (Check the database structure)
    6. TIMESTAMP      (Change the database timestamp)
    7. DATE NEW       (Convert old date formats to smartdate formats)
    8. MDINDEX        (Build/modify a multidimensional index)
  2. Select the REBUILD subcommand by entering:
    REBUILD or 1
  3. Enter the name of the data source to be rebuilt.

    On z/OS, enter the ddname.

    On UNIX, Windows, and OpenVMS, enter filename. The data source to be rebuilt will be referenced by a USE command. If no USE command is in effect, the data source will be searched for using the EDAPATH variable.

  4. If you are simply rebuilding the data source and require no selection tests, enter:
    NO

    The REBUILD procedure will begin immediately.

    On the other hand, if you wish to place screening conditions on the REBUILD subcommand, enter:

    YES

    Then enter the necessary selection tests, ending the last line with ,$.

    Test relations of EQ, NE, LE, GE, LT, GT, CO (contains), and OM (omits) are permitted. Tests are connected with the word AND, and lists of literals may be connected with the OR operator. A comma followed by a dollar sign (,$) is required to terminate any test.

    For example, you might enter the following:

    A EQ A1 OR A2 AND B LT 100 AND
    C GT 400 AND D CO 'CUR',$

Statistics appear when the REBUILD REBUILD procedure is complete, including the number of segments retrieved and the number of segments included in the rebuilt data source.

Example: Using the REBUILD Subcommand in Windows

The following procedure:

 1. REBUILD 
 2. REBUILD 
 3. EMPLOYEE 
 4. NO
  1. Initiates the REBUILD facility.
  2. Specifies the REBUILD subcommand.
  3. Provides the name of the data source to rebuild.
  4. Indicates that no record selection tests are required.

The data source will be rebuilt and the appropriate statistics will be generated.