# Create an Indexed Data File

Use this procedure to create an indexed data file. To create a (record) sequential, line sequential, or relative data file, see Create a Non-indexed Data File.

1. From the Micro Focus Data File Tools window, select File > New, or click (New File).

The New dialog box appears.

2. Select Data File, then click OK.

The Create New File dialog box appears.

3. In the Filename field, type the name of the data file.
Tip: You can specify:
• An absolute path: for example, c:\path\to\file\dat-name.dat (Windows), or /home/path/to/file/dat-name.dat (UNIX).
• A relative path: for example, dat-name.dat. (The .dat file is created in the directory in which Data File Editor was started.)
• A Fileshare path: for example, $$FS-server-name\dat-name.dat (Windows), or$$FS-server-name/dat-name.dat (UNIX).
4. If you are applying a record layout to the data file, click Browse to the right of the Structure File (optional) field, then use the Open dialog box to navigate to and select the structure (.str) file that contains the layout.
5. In the File Details section, click beside Organization, then select Indexed.
6. Click beside Format, then select an indexed file format.
Note: Not all indexed formats are compatible with the editor; those that are not, are not displayed.

For an indexed file, you must specify a primary key, and may specify one or more alternate keys.

7. Click Define Keys.

The Key Information dialog box appears.

1. On the Key tab, click (Insert Before).

A primary key is created, with a default component. A component defines the start position and length of the key within each record.

2. In the Compression section, select the appropriate check boxes:
Removes the leading spaces within the value of the key.
Trailing spaces
Removes the trailing spaces within the value of the key.
Duplicates
For alternate keys only. Only the first duplicate key is contained in the file; subsequent duplicate values are not stored, but information is stored to enable correct recreation of the keys.
3. Click the Component tab.

Details for the default component, created when the key was added, appears.

4. Select Component 0, then specify the Offset and Length values of the primary key.

For example, if the key is going to be the first 3 bytes of the record, specify Offset:0, Length:3.

5. To create a split key, click (Insert After), select the new component and specify the key values.
Tip: To delete a component, select it, then click (Delete).
6. Click OK.

The primary key is created.

9. If required, add an alternate key:
1. Click Define Keys.
2. In the Key section, click (Insert Before).

An Alt Key <number> key is created, with a default component.

3. In the Options section, select the appropriate check boxes:
Allow duplicates
Allows duplicate values for this key.
Sparse
Allows you to define an ANSI or EBCDIC value that when used as the value of this key, will not be stored in the index file; thus saving space.
4. In the Compression section, select the appropriate check boxes:
Removes the leading spaces within the value of the key.
Trailing spaces
Removes the trailing spaces within the value of the key.
Duplicates
For alternate keys only. Only the first duplicate key is contained in the file; subsequent duplicate values are not stored, but information is stored to enable correct recreation of the keys.
5. Click the Component tab.

Details for the default component, created when the key was added, appear.

6. Select the Alt Key, then specify the Offset and Length values.

For example, if the key is going to be the next 3 bytes of the record after the primary key, specify Offset:3, Length:3.

7. To create a split key, click (Insert After), select the new component and specify the key values.
Tip: To delete a component, select it, then click (Delete).
8. Click OK. The alternate key is created.
10. Click beside Encoding, then select either ANSI or EBCDIC.
Note: Once the file is created and open in the editor, you can switch between the two encodings.
11. If the records will be of variable length, select Variable length records.
12. Specify the Min Length (only applicable for variable length records), and Max Length values. All the details you specify in the File Details section are written to the file header of the indexed file.
13. Click Create File.

The file is created, then opened in the editor.