Chapter 14: Rebuilding Indexed Files

This chapter describes the Fix File Index utility that Net Express provides for repairing corrupt indexed files on your PC. Fix File Index is part of the Rebuild utility.

For detailed information about using Fix File Index, see the Net Express online help. (Click Help Topics on the Help menu. Then, on the Contents tab, double-click Development Environment, Working with Data Files, Repairing Indexed Files.)

Overview

There are a number of reasons why an indexed file becomes corrupt. For example:

When a COBOL program tries to open a corrupt indexed file, the run time system detects that the file is corrupt and returns an extended file status code.

Fix File Index can recover corrupt indexed files for you under the following circumstances:

After you have used Fix File Index, you should reorganize the repaired file. For more information, see the section Reorganizing Indexed Files.


Warnings:


Prerequisites

Fix File Index can rebuild only those indexed files that are already in Micro Focus format, which is the format used by Net Express. Therefore, initially you should convert your LEVEL-II V2.5 COBOL files into Micro Focus format, so that you can rebuild the files in the event of corruption. To convert your files, use the Data File Converter (see the chapter Converting Data Files).

Before you rebuild a file, you should take a backup copy of both the index (.idx) and data (.dat) parts of the indexed file.

Rebuilding an Indexed File

To rebuild the index of a corrupt indexed file, you should make sure that the corrupt indexed file is not still open in the Data File Editor. Then, click Data Tools>Fix File Index on the Tools menu.

The Fix File Index dialog box opens:

A screen dump of the Fix File Index dialog box

Figure 14-1: The Fix File Index Dialog Box

You can type in the name of the corrupt indexed file or click Browse to select the file.

If the file header information is not available, Fix File Index displays a warning message. As Fix File cannot derive this information from the file header, you must select a file format and define the file keys. Fix File does not support IDXFORMAT 8 files. To build the index of a file of IDXFORMAT 8 format, use Rebuild from the command line. For more information, see the section Supplying File Header Information.

If the file header information is available, you can recreate the index file by clicking Fix File Index.

Supplying File Header Information

To supply a file header, click Advanced Options on the Fix File Index dialog box.

The Advanced dialog box opens:

A screen dump of the Advanced dialog box

Figure 14-2: Supplying the File Header Information

If the file format information is corrupt, Select a File Format displays as UNKNOWN. In this case, you need to specify the file format, which must be the same as the original file format of the index file before the file became corrupt.

You can ask Fix File Index to carry on processing, after finding a record with duplicate keys, by checking Continue after a duplicate key error?. In this case, Fix File Index reports any records with duplicate keys without writing those records.

You can check whether the key information is corrupt by clicking Define Keys.

Redefining Key Information

When you click Define Keys, the Key Information dialog box opens:

A screen dump of the Key Information dialog box

Figure 14-3: The Key Information Dialog Box

If the Key Information dialog box displays the correct key information, the key information is not corrupt and you can click Cancel and then click FixFile Index to repair the file.

Otherwise, you can click Insert Key to add the first key. At this point, the tree expands and the cursor moves to Key Offset. For each key that you add, you need to supply the following information:

For each key, you can supply additional information under Key Compression and Key Options, where relevant.

The tree structure displays key components as child items. A key may have more than one component. To insert another component, you can highlight a component in the tree and then click on either Insert Component Before or Insert Component After.

You can define more than one key for the index file. To insert another key, highlight a key in the tree and then click on either Insert Key Before or Insert Key After.

When you have finished, you can click OK. Then, to repair the corrupt index file, click Fix File Index in the Fix File Index dialog box.

Reorganizing Indexed Files

You should reorganize an indexed file after you have:

To reorganize an indexed file, use the Data File Converter and specify the same output file and format as the input file. To find out more about the Data File Converter, see the chapter Converting Data Files.

Rebuilding a Duplicate Key Chain

You can use Rebuild to rebuild a duplicate key chain.

The duplicate occurrence value is a unique identifier, which is added to the key, which has duplicates in order to make it unique. When a new key is added, where keys of the same value exist, then the occurrence value of the last added key is incremented by one and used for the newly added key.

If keys are deleted, no change is made to the keys, which are not deleted and so if the highest occurrence of the series of duplicates is not deleted, then the highest value does not change. If the highest occurrence is deleted, then the highest occurrence value reduces to the next lower still existing occurrence value.

For more information on duplicate keys, see the chapter File Organizations.

Validating an Indexed File

The format of the command line for validating a file is:

rebuild in-file /f[c] [d]

You can use Rebuild to validate the structure of an indexed file.

With C-ISAM, IDXFORMAT "3" and IDXFORMAT "4" file formats, a number of validation checks are performed by Rebuild and you can choose to perform all of them or just a sub-set of them. Of course, the more checks you perform, the longer the validation process takes. With other file formats, the additional parameters are not required.

In the following example Rebuild performs a full integrity check on the file:

rebuild test.dat /f:c63d5

Callable Rebuild

You can call Rebuild from your COBOL program as follows:

call "callrb" using commands status

where the parameters are:

commands A PIC X(600) item containing the Rebuild command line. This item must be 600 bytes long because Rebuild scans the command line backwards from offset 599.
status A PIC XX COMP X item containing the returned file status. This item shows the result of the call to Rebuild.

When called from a program, Rebuild does not display any of its usual messages unless you specify the /v option, in which case a running total of the records that are being processed is displayed.

If an error occurs or the rebuild is unsuccessful, RETURN-CODE contains a non-zero value and status contains the returned file status. After a call to Rebuild, you should always check RETURN-CODE and status.

The possible values of RETURN-CODE are shown below.

Value
Description
0 Rebuild executed successfully
1 An error occurred on the input file such as file not found or invalid file format - check status-parameter
2 An error occurred on the output file - check status-parameter
9 The parameter list contained an error such as an invalid option or an invalid combination of options

If an error occurs, execute Rebuild from the command line on the same file with a set of identical parameters. The screen output should give a more precise indication as to the cause of the error.


Note: If you are using the /f option (validate an indexed file), any non-zero RETURN-CODE indicates that the file is corrupt. Again, to obtain more precise information, execute Rebuild from the command line on the same file with a set of identical parameters.


The following example shows Rebuild being called from a COBOL program.

        01 parameters   pic x(600).
        01 status       pic xx comp-x.
        .
        .
        .
        move "infile.dat,outfile.dat /s:lii /c:d1" to parameters
        call "callrb" using parameters,status
        end-call

Error Messages

Rebuild may output error, information or warning messages when rebuilding, converting or reorganizing an indexed file.

A list of Rebuild error messages is given in the Net Express online help. (Click Help Topics on the Help menu. Then, on the Index tab, double-click Rebuild, errors.)


Note: The Fix File Index tool displays file status codes rather than error messages.


Rebuild Examples

The Net Express online help contains a number of Rebuild examples. (Click Help Topics on the Help menu. Then, on the Index tab, double-click Rebuild, examples, and select the one(s) you want to look at.)


Copyright © 2003 Micro Focus International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.