![]() |
![]() |
|
|
|
|
||
|
|
|
|
|
|
||
|
|
In this exercise, you will learn how to convert a line sequential file to a record sequential file and then to create an indexed file from that file. You will also create an indexed file with an alternate index. Another file concept is fixed length records vs. variable length records. In a file with fixed length records, all records have exactly the same length. In a variable length file, each record can be of a different length, but no record should exceed a maximum size. You will need to be aware of the maximum record length for the files you work with. Step 7.1: Start the File Utility Program Begin P-Staff and from the Tools menu select COBFUT32. This action brings up the File Utility Screen. There are only three options:
Click on Commands to start the process.
Figure 7.1 File Utility Window with Commands Menu. Step 7.2: Convert a Line Sequential File The Convert option converts line sequential files to record sequential files. Find the file called Sequence.Dat in Chaptr18, by using Browse. Enter RecSeq.dat into the Output name box. Click OK to begin the process.
Figure 7.2 Convert Window. The Convert process creates a new record sequential file called RecSeq.dat. Convert assumes that the lines in the text (line sequential) file may vary in length. Therefore, it creates a variable length record sequential file. After the process has been run, you should see the completion message.
Figure 7.3 Completion Message. Step 7.3: Browse the File When you have created the file you may want to look at it. Select Browse from the Commands menu. You will then see the Browse dialog window.
Figure 7.4 Browse Dialog Window. Open the RecSeq.dat file into the Input box. Enter the record length (40 in this example). Clicking OK brings up a view of the record in both hexidecimal and character mode. The Browse function allows you to look all of the records in the file but you cannot change them. The hexadecimal format represents the ASCII codes for the characters using the hexadecimal numbering system.
Figure 7.5 Record Contents in Hexadecimal and Character Format. Step 7.4: Load a Sequential File into an Indexed File The Load command creates copies of data files in new formats. Load can only be used with record sequential, indexed, and relative files. We do not deal with relative files, but in this step, you will create an indexed file from RecSeq.dat. Click on Load in the Commands menu to bring up the Load dialog box.
Figure 7.6 Load Dialog Box. Place the path for RecSeq.dat in the Input box and type IdxSeq.dat in the Output box. Make sure that the Organization is IDX and the record format is FIX. The record length is 40. Before creating the file, you will need to establish the KEY. A key is used by indexed files to find individual records. Click on the KEY button to open the Key dialog box. In this case, the key field for the file is a Social Security Number that starts the record. This field is 9 characters long. Enter "(0,9)" into the Primary key box. The first number is the offset from the start of the record and the second number is the length of the field. Since the key starts in the first position of the record, it has an offset of 0.
Figure 7.7 Key Information Dialog Box. Click on OK twice and the new file is created. Click OK a final time after you see a message indicating that all records have been processed.
Figure 7.8 Process Confirmation Message. Step 7.5: Browse the Indexed File Now that you have created an index file, you can look at it in the BROWSE function. Following the procedure in Step 7.3:, open the dialog box, find the proper file and be sure the Organization is IXD.
Figure 7.9 Browse Dialog Box. Click on OK to view the file.
Figure 7.10 Indexed File in Browse Mode. Notice that you have more buttons available to use than with a sequential file. Under Options, you may to choose Character rather than Hexadecimal mode. Experiment with moving around in the file. You may want to perform a search and enter 222222222 into the key field (shown in Red). In browse mode, you cannot change any of the records so don't be afraid to try things. Step 7.6: Create an Alternate Index At times you may need to look at data in sequences different that that of the primary key. Indexed files allow you to create other ways of looking at data called alternate indexes. COBFUT32 does not allow you to add an alternate index to already created index file, but does allow you to define alternate indexes when it is being created. Follow the procedure in Step 7.4: to build a file called IdxSeqA.dat.
Figure 7.11 Load Dialog Box. This time, however, you will be building an alternate key. Click on KEY. Enter the data from Figure 7.12 into the KEY INFORMATION dialog box. The primary key is the same as before. Now, we also want to be able to look up people by their location. This information has an offset of 26 and a length of 3. Since there can be more than one person at a location you need to show duplicates are allowed. Type "D(26,3)" into the Alternate key box and click INSERT. The "D" at the beginning stands for duplicates. You can then click OK twice to create the file.
Figure 7.12 Key Information Dialog Box with Alternate Key. Step 7.7: Browse the File Using the Alternate Index Use the browse option to open IndSeqA.dat. The window looks much the same as it did before.
Figure 7.13 Browse Window Showing Primary Key. Click on Key and highlight the alternate key.
Figure 7.14 Alternate Key Highlighted. Click on OK to reshow the Browse window.
Figure 7.15 Browse Screen with Alternate Key. Notice that now "ATL" is highlighted in red. This is the alternate key field. Use the various buttons to move around in the file and notice how the sequence of records seems to change. The use of the alternate key allows you to move around the same file in more than one sequence. You can see that indexed files can be very useful. |
|
|
||
| © 2003 - 2008 Fujitsu Computer Systems Corporation. All Rights Reserved. |