PreviousMaintaining Files Viewing and Editing Data FilesNext"

Chapter 8: File Handler Utilities (UNIX)

The file handler utilities are a suite of programs provided with Micro Focus COBOL for UNIX that you can use to manage your files.


Note: The file handler utilities remain available in this release of Object COBOL Developer Suite, but are being superceded by an enhanced Rebuild utility. Rebuild is the actively supported and strategic file management utility, while the file handler utilities will be removed from future product updates. For information on how you migrate to Rebuild see the section Migrating To Rebuild.


8.1 Overview

There are seven file handler utilities. Two of these work with all COBOL file organizations:

Utility
Description
fhconvert file conversion utility
fhvalidate file validation utility

The other five utilities only work with indexed files:

Utility
Description
fhcreate builds an empty indexed file
fhedit adds and deletes indices
fhinfo accesses file and index information
fhrebuild re-indexes a corrupt file
fhreorg reorganizes an indexed file

The file handler utilities support five types of indexed file:

Printer sequential (line advancing) files are not supported.

8.2 Parameters

To use the file handler utilities you need to specify a number of parameters. You can do this in one of two ways:

If you supply the parameters via a text file, the first two characters of each record must be the parameter type and the remainder of the record is the parameter value. You can insert comments in a parameter file by preceding the comment with a hash character (#). You also can insert blank lines to make the file more readable.

All output by the utilities is to standard output (stdout), except errors which are output to standard error (stderr).

8.3 Invoking the File Handler Utilities

You can invoke the file handler utilities either from the command line or by calling them from a COBOL program. The following sections describe these methods.

8.3.1 Command Line

To invoke a utility from the command line, specify the utility name, any flags you want to include, plus the name of the parameter file you want to use:

utility-name [-e] [-p filename] [flags] parameter-filename

where the parameters are:

utility-name The name of the utility you want to run.
-e Optional. Suppresses all screen output.
-p Optional. Causes the IN or ON filename to be overwritten by the filename specified after this flag.
filename The name of the file on which you want to run the utility.
flags Optional. One or more of:
-c For use with fhconvert and fhcreate only. Deletes any existing file with the same filename and invokes the -r flag
-f For use with fhinfo and fhvalidate only. Specifies that you want the file information to go to a file. If you do not specify -f, the output goes to standard output (stdout). Any file created using the -f flag can be submitted to other utilities; for example, the fhrebuild utility.
-o For use with fhinfo. Produces output parameters, as opposed to input parameters, to allow the output parameter file to be used as input to fhrebuild.
-r For use with any utility and overwrites any existing temporary work file (filename.con).
-v For use with any utility. Displays the banner giving a version number and copyright.
parameter-filename Either the name of your parameter file, or a minus sign (-) to use parameters from standard input (stdin). See the section Using Standard Input with the Utilities for further information on specifying the minus sign in place of a parameter filename.

8.3.1.1 Using Standard Input with the Utilities

If you specify a minus sign ( - ) instead of a parameter filename, you can enter parameters on the command line. To do this, type the parameters as you would in a parameter file, pressing Enter after each, including the last. When you have entered all the parameters, enter Ctrl+D.

8.3.2 Calling the File Handler Utilities from COBOL

You also can invoke any of the available utilities directly from your COBOL application by incorporating a call to the cobcallfhutil routine. The call has the following format:

call "cobcallfhutil" using by value noargs,
                           by reference arg1,
                                        arg2,
                                        arg3,
                                        arg4,
                                        arg5,
                                        arg6,
                                        arg7,
                                        arg8,
                                        arg9,
                                        arg10
end-call
where all arguments are for input:

noargs A mandatory PIC 9(2) COMP-5 field that contains the number of arguments you supply.
arg1 Mandatory. PIC X(n) field that contains the name of the utility you want to call.
arg2 Mandatory. PIC X(n) field that contains the first utility argument.

A utility argument can be -e, -p, the name of the file on which you want to run the utility, any of the flags -c, -f, -o, -r or -v, the name of your parameter file or a minus sign ( - ). See the section Command Line above for descriptions of these parameters.

arg3 Optional. PIC X(n) field containing the second argument.
arg4 Optional. PIC X(n) field containing the third argument.
arg5 Optional. PIC X(n) field containing the fourth argument.
arg6 Optional. PIC X(n) field containing the fifth argument.
arg7 Optional. PIC X(n) field containing the sixth argument.
arg8 Optional. PIC X(n) field containing the seventh argument.
arg9 Optional. PIC X(n) field containing the eighth argument.
arg10 Optional. PIC X(n) field containing the ninth argument.

The RETURN-CODE contains either zero for successful completion, or non-zero if the utility fails.

8.4 Record Delimiters

Records in relative, line sequential and fixed record length indexed files are terminated by one of two record delimiters. These are:

If the delimiter needs to be specified for a utility, it is specified in the parameter file used by the utility.

You should not specify a record delimiter for record sequential files or variable record length indexed files.

8.5 Default File Type Parameters

The following two tables list default file type parameters, where the first character is a letter and the second character is a digit. Table 8-1 shows the file type parameters for UNIX and Table 8-2 shows the file type parameters for DOS and OS/2.

Table 8-1: Default UNIX File Type Parameters

  File Type Delimiter Block Size
Indexed Fixed I0 N/A 1023
Indexed Variable I3 N/A 1023
Relative Fixed R0 0 N/A
Relative Variable R0 1 N/A
Sequential Fixed S0 N/A N/A
Sequential Variable S0 N/A N/A
Line Sequential L0 1 N/A
IDXFORMAT"4" indexed I4 N/A 1023

Note: Throughout this chapter, I0 indicates a C-ISAM file created using either the modified C-ISAM file handler provided with this COBOL system, or the standard C-ISAM file handler, while I3 indicates a Micro Focus COBOL indexed file, that is, an indexed file with variable length records, data compression or created by a program compiled using IDXFORMAT"3".


Table 8-2 is included so that you are aware of the differences should you want to convert files created on DOS or OS/2 systems to UNIX.

Table 8-2: Default DOS and OS/2 File Type Parameters

  File Type Delimiter Block Size
Indexed Fixed I3 N/A 1023
Indexed Variable I3 N/A 1023
Relative Fixed R0 1 N/A
Relative Variable R0 1 N/A
Sequential Fixed S0 N/A N/A
Sequential Variable S0 N/A N/A
Line Sequential L0 0 N/A
IDXFORMAT(4) indexed I4 N/A 1023

8.6 Default Index Block Size

The file handler utilities use a default block size of 1 kilobyte (1K), identical to the run-time system indexed file block size.

You can alter this default setting by setting the run-time tunable isam_block_size. See your Object COBOL User Guide for details.

8.7 Use of Keys in Indexed Files

When you create an indexed file, a primary index is created that can never be deleted.

When you set up a key, each key can be multi-part and each part can be in a different area of the record; these do not have to be contiguous and do not have to exist in any particular order. All keys, other than the primary key, can hold duplicate values.

Keys are specified by a key description.

This description takes the following format:

[compression-type] (m:n:xxx/m:n:xxx/....)

where the parameters are:

compression-type Optional. Can consist of:

C - all compression

or any combination of:

D - duplicates allowed
S - same key (duplicate) compression
L - leading compression
T - trailing compression

m The start offset of the key in a record
n The key length
xxx The key type, that must currently be CHAR or CHARTYPE

For example, to specify a prime key of length four bytes starting at record offset zero, the entry would be:

PK (0:4:CHAR)

and to specify a multi-part alternate key for which duplicates are permitted with key compression, the first part starting at record offset four having length two bytes and the second part starting at record offset twelve having length six bytes would be:

AK DS (4:2:CHAR/12:6:CHAR)

To specify the key offset and key length, you can use any combination of size mnemonics, digits and arithmetic calculations (addition, subtraction, multiplication and division) including parentheses. The precedence for arithmetic calculations is as follows:

( ) parentheses
* / multiplication and division
+ - addition and subtraction

Calculations are performed from left to right; integer values only are accepted (no decimal values are accepted). You cannot use negative numbers.

Consider the following examples:

10 + 6  / 2 = 10 + 3 = 13
(10 + 6) / 2 = 16 / 2 = 8

The section Example fhconvert Parameter File, that gives an example of a parameter file, illustrates the ways you can give key descriptions.

Indexed files can hold a number of indices. Further indices can be added to files, by using the utility fhedit.

These utilities also support compressed indexed files of the type used by this COBOL system.

8.8 Error Handling

If you specify the -e option, any error messages are suppressed. We recommend that you specify the -e option as the first flag to suppress command line parsing errors.

When calling the utilities from COBOL, a file status and the RETURN-CODE are available to the calling program. The file status is returned in the external data item cob_util_last_error . The example code below demonstrates how to define and access the external data item cob_util_last_error. (The demonstration program, validate2, supplied with the file handler utilities, makes use of cob_util_last_error.)

 working-storage section.

* Utility arguments

* external status and decoding variables

 01 cob-util-last-error external.
     03 status-1  PIC X.
     03 status-2  PIC X.
     03 status-2-9 redefines status-2  PIC 9.
 01 reply-bin redefines cob-util-last-error  PIC 9(4) comp.

 01 reply-decode.
     03 reply-1   PIC X.
     03 reply-2   PIC 999.

 procedure division.

* Code to call the utilities

     perform get-file-status

* Status handling code

     stop run.
* Decode the returned 2 byte status 
 get-file-status.
     move status-1 to reply-1
     if reply-1 not=9
         move status-2-9 to reply-2
     else
         move low-values to status-1
         move reply-bin to reply-2
     end-if

This file status data item is available when calling the utilities from any language. In non-COBOL calling programs, the external variable should be referenced as cob_util_last_error. For COBOL, use hyphens instead of underscores.

8.8.1 Error Conditions

There are two possible types of error condition:

Details of utility errors can be found in the section Utility Error Messages. If the error indicates you have given invalid or duplicate parameters, the error message always displays the parameter file entry that is at fault.

For each file type two error variables are used: the error number and the error status. The names of these variables differ according to the file type. They are:

Status Variables
File Type
Error Number
Status 1
Status 2
indexed iserrno isstat1 isstat2
relative rlerrno rlstat1 rlstat2
sequential sqerrno sqstat1 sqstat2
line sequential lserrno lsstat1 lsstat2

You can find full details of the error number and status variables in the section Utility Error Messages.

For UNIX operating system errors, the value of errno, is displayed in the error message. For more information consult your operating system documentation.

8.9 Creating Statically Linked Executable Files

By default, any statically linked executable files created by your COBOL system exclude the file handler utilities.

The utilities are, however, included if your COBOL program contains a reference to the utility entry point cobcallfhutil. Alternatively, you can ensure that the utilities are included by using the -I fhutil option on your cob command line. For example:

cob -xvo newrts32 prog1.o prog2.o -I fhutil

8.10 fhconvert

The fhconvert utility enables you to convert a file. You can change:

8.10.1 fhconvert Parameters

Parameter Type
Parameter Value

Description
IN xxxxxxxxxx Input filename (length is operating system dependent).
IE Optional. If omitted, .dat extension assumed for input file.
IT xx Input file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the formatused by this COBOL system
I4 IDXFORMAT"4"
R0 Relative
S0 Sequential
L0 Line sequential
ID n Optional - record delimiter (omit for indexed and sequential files):

0 = LF (default)
1 = CR and LF

IF nnnn Fixed record length in bytes (omit for indexed files).
IV mmmm/nnnn Variable record length minimum (m), maximum (n) (omit for indexed files).
ON xxxxxxxxxx Output filename
OT xx Output file types. As input file types above.
OD n Optional - record delimiter (omit for indexed and sequential files):

0 = LF (default)
1 = CR and LF

OF nnnn Fixed record length in bytes
OV mmmm/nnnn Variable record length, minimum (m), maximum (n)

In addition, the following information refers to indexed files only:

Parameter Type
Parameter Value

Description
OB nnnn Index block size 511, 1023 or 4095.
OE Optional. If omitted, .dat extension assumed for output file.
NL xxxxx.... Optional - NLS language name.
PK DSLTC (m:n:xxx:m:n:xxx/...) Primary key description.
AK DSLTC (m:n:xxx:m:n:xxx/...) Optional - alternate key description, one for each alternate key used in the file.
DC nnn Optional - data compression type (0 - 255, indexed and sequential files only)

8.10.2 fhconvert Errors

fhconvert gives the following warning message if you include the input record size for an indexed file:

(IF/IV) Record length is ignored for input ISAM file

You do not need to give this information as fhconvert takes these details from the file (you must include this information for other file types). This is only a warning message; the utility should run normally unless an error situation is detected.

If you include a record delimiter in the parameter file for a record sequential file, the following warning message is displayed:

Record delimiter has been specified for sequential file

The utility ignores the record delimiter as it is not applicable to record sequential files, and continues as normal.

If you specify data compression for an indexed output file type other than I3, I4 or S0, the following warning message is displayed:

Data compression only valid for file types I3, I4 and S0, file type updated

fhconvert automatically selects the I3 file type to enable data compression to be used. If you specify data compression for a relative or line sequential file the following warning message is displayed:

Data compression only valid for ISAM files - ignored

fhconvert automatically disregards the data compression specified. If an error is detected, the utility closes all files, then terminates, displaying a message on the screen indicating the type of error detected.

8.11 fhcreate

The fhcreate utility enables you to create an empty indexed file . You may find this utility particularly useful in situations where an application needs a file to exist but not necessarily hold any data.

8.11.1 fhcreate Parameters

Parameter Type
Parameter Value
Description
ON xxxxxxxxxx Output filename (length is operating system dependent).
OT xx Output file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the format used by this COBOL system
I4 IDXFORMAT"4" indexed
OF nnnn Fixed record length in bytes (n)
OV mmmm/nnnn Variable record length, minimum (m), maximum (n)
OB nnnn Optional - index block size 511, 1023 or 4095
OE Optional. If omitted, .dat extension assumed for output file.
NL Optional - NLS language name
PK DSLTC (m:n:xxx/m:n:xxx/...) Primary key description
AK DSLTC (m:n:xxx/m:n:xxx/...) Optional - alternate key description, one for each alternate key used in the file
DC nnn Optional - data compression type (0 - 255, indexed files and sequential files only)

8.11.2 fhcreate Errors

If an error is detected, fhcreate closes all files, then terminates, displaying a message on the screen indicating the type of error detected.

If you specify a data compression type (other than 0) for an indexed file type other than I3 or I4, the following warning message is displayed:

Data compression only valid for files type I3, I4 or S0, file type updated to I3

fhcreate automatically selects the I3 file type to enable data compression to be used.

8.12 fhedit

The fhedit utility enables you to alter indices in an indexed file. There are two main functions:

You cannot delete the primary index using this utility.

You can use fhedit with the fhvalidate utility to repair corrupt indices. The fhvalidate utility gives details of the corrupt indices in the file.

8.12.1 fhedit Parameters

Parameter Type
Parameter Value

Description
IN xxxxxxxxxx Input filename (length is operating system dependent).
IE Optional. If omitted, .dat extension assumed for input file.
IT xx Optional - input file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the format used by this COBOL system
NL xxxxx Optional - NLS language name.
AK DSCTL (m:n:xxx/m:n:xxx/...) Alternate key description to be added.
DK DSCTL (m:n:xxx/m:n:xxx/...) Alternate key description of the key to be deleted.


Note: You cannot use fhedit with IDXFORMAT"4" indexed files.


8.13 fhinfo

The fhinfo utility enables you to obtain information about an existing indexed file. This information consists of file and index information.


Note: The number of records in a variable format file or a data compressed file cannot be determined and is given as -1.


8.13.1 fhinfo Parameters

Parameter Type
Parameter Value

Description
IN xxxxxxxxxx Input filename (length is operating system dependent)
IT xx Optional - input file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the formatused by this COBOLsystem
I4 IDXFORMAT"4" indexed
IE Optional. If omitted, .dat extension assumed for input file.

Example

The fhinfo parameter file using the listed parameter types on a C-ISAM file called test, where the physical files created are test and test.idx is:

IN test     # input filename
IT I0       # C-ISAM file
IE          # is required when the data part is
              created as test rather than test.dat.

8.14 fhrebuild

The fhrebuild utility enables you to re-index a corrupt indexed file. You need to supply details of all the indices you want to create. You can also use this utility with the fhvalidate utility to repair a corrupt file. (You can use the Rebuild utility, which provides additional functionality and greater flexibility, to perform these tasks. See the chapter Maintaining Files for details on Rebuild.)

When using fhrebuild, you must always rebuild the file in the same format as the original file for the following parameters:

You can use fhvalidate to produce a parameter file which is used as input to fhrebuild.

If successful, fhrebuild replaces the existing file with the newly indexed file. However, inconsistencies in the data file can render an indexed file incapable of being rebuilt. If fhrebuild fails, the file is left in the same condition as before and an appropriate error message is displayed.

8.14.1 fhrebuild Parameters

The parameter file records are:

Parameter Type
Parameter Value

Description
ON xxxxxxxxxx Output filename (length is operating system dependent).
OT xx Output file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the formatused by this COBOL system
I4 IDXFORMAT"4" indexed
OF nnnn Fixed record length in bytes (n)
OV mmmm/nnnn Variable record length, minimum (m), maximum (n)
OB nnnn Optional - index block size 511, 1023 or 4095
OE Optional. If omitted, .dat extension assumed for output file.
NL xxxx.... Optional - NLS language name
PK DSLTC (m:n:xxx/m:n:xxx/...) Primary key description
AK DSLTC (m:n:xxx/m:n:xxx/...) Optional - alternate key description, one for each alternate key used in file
DC nnn Optional - data compression type (0 -255)

For more information on keys, see the section Use of Keys in Indexed Files earlier in this chapter.

8.15 fhreorg

The fhreorg utility enables you to reorganize an indexed file using a specified key. Reorganizing a file using the most commonly accessed key can improve performance.

8.15.1 fhreorg Parameters

Parameter Type
Parameter Value

Description
IN xxxxxxxxxx Input filename (length is operating system dependent).
IE Optional. If omitted, .dat extension assumed for input file.
IT xx Input file type. File types are:

I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the formatused by this COBOL system
I4 IDXFORMAT"4" indexed
KN xxx Key number of access key (1 = prime)
ON xxxxxxxxxx Output filename (length is operating system dependent).
OE Optional. If omitted, .dat extension assumed for output file.
OT xx Output file type. File types are as for IT parameter above.
PK DSLTC(m:n:xxx/..) Primary key description for output file.
AK DSLTC (m:n:xxx/..) Optional - alternate key descriptions for output file.
KO x Record retrieval order:

0 = ascending order
1 = descending order

DC xxx Optional - output file data compression type.

8.16 fhvalidate

The fhvalidate utility enables you to validate a file. It produces a simple report indicating success or failure.

For indexed files, additional information about corrupt indices is produced. You can use this information as a parameter file with fhedit and fhrebuild to re-index the file.


Note: You can use the Rebuild utility (see the chapter Maintaining Files for details) to carry out a more thorough validation of Micro Focus format indexed files.


8.16.1 fhvalidate Parameters


Note: When using fhvalidate, you do not need to enter the record length for indexed files.

If your file uses data compression you must specify a file type of I3 or I4.


Parameter Type
Parameter Value

Description
IN xxxxxxxxxx Input filename (length is operating system dependent).
IT xx Input file type. File types are:
I0 C-ISAM
I1 X/Open
I2 LEVEL II indexed
I3 Indexed files of the formatused by this COBOL system
I4 IDXFORMAT"4" indexed
R0 Relative
S0 Sequential
L0 Line sequential
IE Optional. If omitted, .dat extension assumed for input file.
ID n Optional. Record delimiter (omit for indexed and sequential files):

0 = LF (default)
1 = CR and LF

IF nnnn Fixed record length in bytes (not needed for indexed files).
IV mmmm/nnnn Variable record length minimum (m), maximum (n) (not needed for indexed files).

8.16.2 Validation Information Messages

The following information messages are displayed by fhvalidate:

# Cannot recover from previous error, quitting file validation
# Error - Index entries inconsistent with records on data file
# Error detected on index nn, record nn. (iserrno = )
# Error detected on index nn. (iserrno = )
# Error - Index record size incorrect
# Error reading record nn in filename. (errno)
# File needs to be edited. Creating parameter file for fhedit
# File needs to be rebuilt. Creating parameter file for fhrebuild
# Record length of record nn or record nn is inconsistent
Validation of file was successful filename
Validation of file was unsuccessful filename

8.16.2.1 fhvalidate Errors

fhvalidate gives the following warning message if you include an input record size for indexed files:

(IF/IV) Record length is ignored for input ISAM file

You do not need to give this information as fhvalidate takes these details from the file (you must include this information for other file types). This is only a warning message. fhvalidate should run normally unless an error situation is detected.

If you include a record delimiter in the parameter file for an indexed or sequential file you see one of the following warning messages:

Record delimiter has been specified for ISAM file
Record delimiter has been specified for sequential file

fhvalidate ignores the record delimiter as it is not applicable to indexed or sequential files, and continues as normal.

8.17 Demonstration Programs

The directory $COBDIR/demo/fhutils contains a number of programs that demonstrate how to use the file handler utilities.

Before using the demonstrations, you need to change to the $COBDIR/demo/fhutils directory and set up the files. To change directory, type:

cd $COBDIR/demo/fhutils 

Then type:

setup

to set up the files.

Running the setup program removes any files that were created by previously running these demonstration programs, and reinstates the supplied corrupt file, badfile, used in the demonstrations. It also ensures that all the necessary files are in $COBDIR/demo/fhutils.

All the programs have been compiled for animation.

8.17.1 demo1

The demo1 demonstration program uses the file handler utility fhinfo to obtain information about a file and its index. Use of fhinfo is restricted to indexed files.

demo1 uses the following six files:

info1.int (info1.cbl, info1.idy)
info1a.int (info1a.cbl, info1a.idy)
info1.inf
info2.int (info2.cbl, info2.idy)
info2a.int (info2a.cbl, info2a.idy)
info2.inf

The files are described in the following sections in the order in which they are used.

8.17.1.1 info1 Demonstration Program

Run the info1 demonstration program by typing:

cobrun info1.int

Running the info1 demonstration program creates an indexed file called demofile with fixed length records, and writes one record to the file.

8.17.1.2 info1.inf Parameter File

The info1.inf parameter file is used by fhinfo to obtain information about the file demofile that you created by running the info1 demonstration program:

IN demofile 
IE

IN specifies the file about which you want to obtain information and IE specifies that the data file has no .dat extension.

Run the fhinfo utility by typing:

fhinfo -rv info1.inf

The following information is displayed:

IN demofile 
IE 
IT I0 
IF 20 
# Number of records - 1 
# Block size - 1023 
NL n-computer 
PK (0:8:CHARTYPE) 
AK D(8:4:CHARTYPE) 
AK (12:4:CHARTYPE) 
AK (16:4:CHARTYPE)

You can look at the source code of the program that created this file (info1.cbl) to see how the information displayed by fhinfo relates to the key and record definitions for the file.

Now run the fhinfo utility by typing:

fhinfo -f output -rv info1.inf

This time the information is sent to an output file called output which can be used as an input parameter file for other utilities - See the section Rebuilding a File using the -o Option.

8.17.1.3 info1a Demonstration Program

Run the info1a demonstration program by typing:

cobrun info1a.int

Running this program is equivalent to entering the command fhinfo -rv info1.

8.17.1.4 info2 Demonstration Program

The info2 demonstration program creates a file called demofile2, an indexed file with variable length records.

Run the info2 program by typing:

cobrun info2.int

8.17.1.5 info2.inf Parameter File

The info2.inf parameter file is used by fhinfo to obtain information about demofile2:

IN demofile2 
IE

IN specifies the file about which you want to obtain information and IE specifies that the data file has no .dat extension.

Run the fhinfo utility by typing:

fhinfo -rv info2.inf

The following information is displayed:

IN demofile2 
IE 
IT I3 
IV 20/30 
# Number of records -  -1 
# Block size - 1023 
NL n-computer 
PK (0:8:CHARTYPE) 
AK D(8:4:CHARTYPE) 
AK (12:4:CHARTYPE) 
AK (16:4:CHARTYPE) 

You can use the parameter file info1.inf:

IN demofile 
IE

to obtain information about demofile2 by typing:

fhinfo -p demofile2 -rv info1.inf

This causes the demofile reference in the parameter file to be overwritten with the filename demofile2 at execution time.

8.17.1.6 info2a Demonstration Program

Run the info2a demonstration program by typing:

cobrun info2a.int

Running this program is equivalent to entering the command fhinfo -rv info2.

8.17.2 demo2 Demonstration Program

The demo2 demonstration program uses the file handler utilities fhcreate and fhedit to create an empty indexed file and then add and delete alternate keys.

demo2 uses the following six files:

create.cre
create.int (create.cbl, create.idy)
create.inf
edit.edi
edit.int (edit.cbl, edit.idy)
edit2.int (edit2.cbl, edit2.idy)

The files are described in the following sections in the order in which they are used.

8.17.2.1 create.cre Parameter File

The create.cre parameter file enables fhcreate to create an indexed file identical to the one you created by running info1 using demo1:

ON demofile3        # filename of file to be created 
OE                  # no .dat extension
OT I0               # indexed fixed
OF 20               # fixed record length of 20 bytes
PK (0:8:CHARTYPE)   # Prime key 
AK D(8:4:CHARTYPE)  # An alternate key with duplicates allowed
AK (12:4:CHARTYPE)  # Another alternate key 
AK (16:4:CHARTYPE)  # And yet another

Create an empty indexed file by typing:

fhcreate -cv create.cre

where:

-c tells fhcreate to remove any work files and the indexed file demofile3 if it exists.

8.17.2.2 create.inf Parameter File

The create.inf parameter file enables the fhinfo utility to obtain information about the empty indexed file you created using create.cre:

fhinfo -rv create.inf

You can use fhinfo with fhcreate to create a file like demofile. To do this, you need to use fhinfo to obtain information about demofile. Although this produces all the information you require, the parameter types are incorrect; that is, fhinfo creates IN, IT, and so on, whereas fhcreate requires ON, OT, and so on. To change the parameter types to those required by fhcreate, run fhinfo with the -o option, for example:

fhinfo -orv create.inf

So, to create a copy of the file you created by running info1, type:

fhinfo -orv info1.inf | fhcreate -p demofile3 -cv -

The minus sign ( - ) at the end of the command line specifies that fhcreate takes its input from standard input (stdin) rather than a parameter file and so the UNIX pipe command ( | ) redirects the output from fhinfo to fhcreate. The -p option specifies that the filename read in by fhcreate is to be replaced by the filename specified on the command line, demofile3.

8.17.2.3 create Demonstration Program

The create demonstration program contains code that calls fhcreate. To run the create program, type:

cobrun create.int

8.17.2.4 edit.edi Parameter File

The edit.edi parameter file contains parameters that allow fhedit to add and remove alternate keys from the file you have just created (demofile3):

IN demofile3            # The filename 
IT I0                   # indexed fixed
IE                      # no .dat extension
AK DC(7:1:CHARTYPE)     # Add a key with duplicates allowed and
                          compression
DK (12:4:CHARTYPE)      # Delete a key 
AK (12:2:CHARTYPE)      # And add another

To add these keys to your newly created file (demofile3), type:

fhedit -rv edit.edi

You can now re-run fhinfo to view the altered file:

fhinfo -rv create.inf

8.17.2.5 edit Demonstration Program

The edit demonstration program contains code that performs a read and write to an edited file. You can view the source of this program in edit.cbl. To run this program, type:

cobrun edit.int

8.17.2.6 edit2 Demonstration Program

The edit2 demonstration program contains code for the fhedit call used in the section edit.edi Parameter File, above. If you have already run fhedit, you must re-run fhcreate before continuing. To run edit2:

cobrun edit2.int

8.17.3 demo3 Demonstration Program

The demo3 demonstration program uses the file handler utilities fhvalidate and fhrebuild to validate a file and then rebuild it.

To demonstrate the use of these two utilities, a corrupt file, badfile and its index file badfile.idx are supplied. When you run setup, these files are copied to the indexed files corrupt and corrupt.idx, the files that you actually use.

demo3 uses the following six files:

validate.val
validate2.int (validate2.cbl, validate2.idy)
info.inf
rebuild.int (rebuild.cbl, rebuild.idy)
validate.int (validate.cbl, validate.idy)
validate.inf

The files are described in the following sections in the order in which they are used.

8.17.3.1 validate Demonstration Program

The validate demonstration program contains code to read and write to the indexed file corrupt:

cobrun validate.int

An error occurs indicating that the file is corrupt. You can validate the file and rebuild it so that next time you run validate, the error does not occur and the reads and writes to the file are successful.

8.17.3.2 validate.val Parameter File

The validate.val parameter file is used by fhvalidate to validate the corrupt indexed file corrupt:

IN corrupt  # the corrupt files name
IT I0       # indexed fixed 
IE          # no .dat extension

To validate corrupt, type:

fhvalidate -rv validate.val

Firstly, fhvalidate reads the file sequentially. Next, it performs random reads on each of the keys. fhvalidate detects an error on record 8/7 and produces output that can be used with fhrebuild to rebuild corrupt. As you can see, the output is displayed on the screen; you need to place the output in a file so that you can use it as a parameter file to rebuild corrupt. To do this, re-run the fhvalidate utility by typing:

fhvalidate -f rebuild.reb -rv validate.val

This places the output in a file that, in this demonstration, is called rebuild.reb. You can now use rebuild.reb to rebuild the corrupt file:

fhrebuild -rv rebuild.reb

If you now re-run the validate demonstration program by typing:

cobrun validate.int

you can see that the reads and writes are successful. If you want to verify that the file has been successfully rebuilt, re-run fhvalidate as follows:

fhvalidate -rv validate.val
8.17.3.2.1 Rebuilding a File without using a Parameter file

You can use the UNIX pipe command to redirect the output from fhvalidate to fhrebuild, without creating a parameter file:

fhvalidate -rv validate.val | fhrebuild -rv -
8.17.3.2.2 Rebuilding a File using the -o Option

You can use the -o option so that the output from fhinfo can be used as input to fhvalidate:

fhinfo -orv validate.val | fhrebuild -rv -
8.17.3.2.3 Combining fhinfo and fhrebuild to Rebuild a File

To rebuild a file using fhinfo and fhvalidate, type:

fhinfo -f rebuild.reb -orv validate.val
fhrebuild -rv rebuild.reb

8.17.3.3 validate2 Demonstration Program

The validate2 demonstration program validates the file corrupt:

cobrun validate2.int

When you run validate2 the file status returned by fhvalidate is displayed.

8.17.3.4 rebuild Demonstration Program

The rebuild demonstration program contains code that performs a call to fhrebuild to rebuild the corrupt file. Before running this utility, the file rebuild.reb must exist. To run this program, type:

cobrun rebuild.int

8.17.3.5 validate.inf Parameter File

The validate.inf parameter file provides parameters that enable fhinfo to obtain file information on the file corrupt. To run this utility, type:

fhinfo -rv validate.inf

8.17.4 demo4 Demonstration Program

The demo4 demonstration program uses fhconvert to convert a file.

demo4 uses the following six files:

convert.int (convert.cbl, convert.idy)
convert.ind
convert.inf
convert.seq
convert.lsq
convert.rel

These files are described in the following sections. You can use them in any order, as long as you run the convert demonstration program first.

8.17.4.1 convert Demonstration Program

The convert demonstration program creates and writes records to an indexed file containing fixed length records. This file has data compression and key compression active. To create the file demofile4, type:

cobrun convert.int

8.17.4.2 convert.inf Parameter File

The convert.int parameter file enables fhinfo to obtain information about the data and index of the demofile4:

fhinfo -rv convert.inf

8.17.4.3 convert.rel Parameter File

The convert.rel parameter file enables fhconvert to convert the indexed file demofile4 to a relative file, demofile8:

IN demofile4    # Input indexed file
IE              # no .dat extension 
IT I3           # Input type 
ON demofile8    # Output filename
OT R0           # File type relative 
OE              # no .dat extension 
OF 20           # Fixed record length of 20 bytes

To convert demofile4 to a relative file, type:

fhconvert -rv convert.rel

8.17.4.4 convert.seq Parameter File

The convert.seq parameter file enables fhconvert to convert the indexed file demofile4 to the sequential file demofile6. The parameters are:

IN demofile4    # indexed input file
IE              # no .dat 
IT I3           # Input type 
ON demofile6    # output filename
OT S0           # Sequential output type 
OE              # no .dat extension 
OF 20           # fixed records of 20 bytes 

To convert demofile4 to a sequential file, type:

fhconvert -rv convert.seq

8.17.4.5 convert.lsq Parameter File

The convert.lsq parameter file enables fhconvert to convert the indexed file demofile4 to the line sequential file demofile7:

IN demofile4    # indexed input file
IE              # no .dat 
IT I3           # Input type 
ON demofile7    # output filename
OT L0           # output type L0 
OV 20/21        # variable length record varying 20 to 21
OE              # no .dat extension 

To convert demofile4 to a line sequential file, type:

fhconvert -rv convert.lsq

8.17.4.6 convert.ind Parameter File

The convert.ind parameter file enables fhconvert to convert the compressed indexed file demofile4 to the uncompressed indexed file demofile5:

IN demofile4    # indexed input file
IE              # no .dat 
IT I3           # Input type 
ON demofile5    # output filename
OT I3           # output type 
OE              # no .dat extension 
OF 20           # fixed length records of 20 bytes 

To convert demofile4 to an uncompressed indexed file, type:

fhconvert -rv convert.ind

8.17.5 demo5 Demonstration Program

The demo5 demonstration program uses fhreorg to reorganize an indexed file on a specified key, in either descending or ascending order.

demo5 uses the following four files:

reorg1.int (reorg1.cbl, reorg1.idy)
reorg2.int (reorg2.cbl, reorg2.idy)
reorg3.int (reorg3.cbl, reorg.idy)
reorg.reo

The files are described in the following sections in the order in which they are used.

8.17.5.1 reorg1 Demonstration Program

Run the reorg1.cbl demonstration program by typing:

cobrun reorg1.int

This creates an indexed file, demofile9 with fixed length records and one alternate key. The program writes four records and the contents of the keys are displayed as they are written.

8.17.5.2 reorg.reo Parameter File

The reorg.reo parameter file is used by fhreorg to create a copy of demofile9 called demofile10 with the data portion of the file organized on ascending alternate key 1:

IN demofile9       # filename of file to be reorganized
IE                 # no .dat extension
IT I0              # indexed fixed
KO 0               # ascending
KN 2               # key-2 (alternate key 1)
ON demofile10      # filename of reorganized file
OT I0              # indexed fixed
OE                 # no .dat extension
PK (0:4:CHARTYPE)  # prime key

Run the fhreorg utility by typing:

fhreorg -crv reorg.reo

8.17.5.3 reorg2 Demonstration Program

Running reorg2 is equivalent to entering the command fhreorg -crv reorg.reo. To run the program, type:

cobrun reorg2.int

8.17.5.4 reorg3 Demonstration Program

The reorg3 demonstration program reads the data portion of the reorganized file demofile10 as a relative file and displays the records as they are read. To run the program, type:

cobrun reorg3.int

As you can see, the records are now displayed in reverse order.

8.18 Example fhconvert Parameter File

This example parameter file below converts a relative file to a C-ISAM file.

All parameters can be specified in upper or lower case (except path and filenames which are case sensitive). Tab characters and spaces are interchangeable. There is no significance in the order in which the parameters are written.

# parameter file used to convert a relative file to an indexed file 
# input parameters
IN rel-file              # input file name
IT R0                    # input file type - relative
ID 0                     # LF record delimiter
IF 240                   # fixed record length
# Output parameters 
ON /pathname/isam-file   # output file name 
OT I0                    # output file type - C-ISAM
OV 200/240               # Variable record length 200 min/240 max

OB 511                   # block size (optional)

PK D(129:29:Chartype)    # Prime key description 
                         # key can have duplicates
                         # start byte is 129
                         # key length is 29
                         # key type is CHARTYPE
AK C (160 4:CHARTYPE)    # Alternate key description 
                         # key has compression
                         # start byte is 160
                         # key length is 4
                         # key type is CHARTYPE


AK (164:10*CHARSIZE:CHARTYPE)    # Alternate key description 
                                 # start byte is 164
                                 # key length is CHARSIZE*10
                                 # key type is CHARTYPE

DC 001                           # data compression type 1 for
                                 # output ISAM file
                                 # (This will automatically
                                 # change OT from I0 to I3)
#------------------ end of parameter file ------------------ 

8.19 Utility Error Messages

This section lists the error messages displayed by the file handler utilities. In addition to the error message, further information may be displayed, as follows:

8.19.1 Error Messages

Block size specified more than once
Cannot build isam file filename (iserrno = )
Cannot build line sequential file filename (lsstat1/lsstat2)
Cannot build relative file filename (rlstat1/rlstat2)
Cannot build sequential file filename (sqstat1/sqstat2)
Cannot delete file filename (iserrno = /status1 & 2)
Cannot initialize correct language support
Cannot open configuration file filename (errno)
Cannot open file filename (iserrno/status1 & 2)
Cannot open isam file filename (iserrno)
Cannot open line sequential file filename (lsstat1/lsstat2)
Cannot open parameter file filename (errno)
Cannot open relative file filename (rlstat1 rlstat2)
Collating sequence specified more than once
Cannot open sequential file filename (sqstat1 sqstat2)
Configuration file exists
Error encountered while adding an index filename (iserrno)
Error encountered while deleting an index filename (iserrno)
Error encountered while linking file filename (errno)
Error encountered while obtaining file information filename (iserrno)
Error encountered while reading the file filename (iserrno/status1 & 2)
Error encountered while unlinking the file filename (errno)
Error encountered while writing the file filename (iserrno/status1 & 2)
File name specified more than once
File type specified more than once
Fixed and variable record length specified for input file
Fixed and variable record length specified for output file
Fixed record length specified more than once
Illegal configuration filename filename (errno)
Illegal flag flag
Illegal parameter filename filename (errno)
Incorrect permissions on configuration file filename (errno)
Incorrect specification of collating sequence
Incorrect permissions, or file is locked filename (iserrno)
Incorrect specification of block size
Incorrect specification of input record delimiter record
Incorrect specification of output record delimiter
Incorrect specification of NLS language
Input extension specified more than once
Input file name (IN) illegal
Input file type (IT) illegal
Input file. Minimum record length > maximum record length
Input name and Output name should not be identical
Input record delimiter specified more than once
Input record length not specified
INTERNAL ERROR: Illegal function pointer
Invalid block size, only 4095/1023/511 are supported
Invalid definition of file type
Invalid definition of fixed record length
Invalid definition of variable record lengths
Invalid key description
Invalid key type
Line sequential file can only be opened/built variable length
Memory allocation error (errno)
NLS language specified more than once
Null or illegal file name specified for use with the '-f' flag
Null or illegal file name specified for use with the '-p' flag
Output extension specified more than once record
Output file. Minimum record length > maximum record length
Output file name (ON) illegal
Output file type (OT) illegal
Output record delimiter specified more than once
Output record length not specified
Parameter file not specified
Prime key description specified more than once
Unrecognised parameter in parameter file
Utility not supported
Variable record length specified more than once

8.19.2 File-specific Error Codes

Certain errors are associated only with C-ISAM and X/Open compliant files. Therefore, the following sections are divided between C-ISAM and X/Open compliant files and other file types.

8.19.2.1 Errors Associated with C-ISAM and X/Open Files

Error numbers are from -1 to 99 for operating system errors and greater than 99 for other errors. Unlike the other file types, the errors are identified by the error number, rather than the status codes.

EDUPL Duplicate record
ENOTOPEN File not open
EBADARG Illegal argument
EBADKEY Illegal key description
ETOOMANY Too many files open
EBADFILE Bad ISAM file format
ENOTEXCL Non-exclusive access
ELOCKED Record locked
EKEXISTS Key already exists
EPRIMEKEY Is primary key
EENDFILE End/begin of file
ENOREC No record found
ENOCURR No current record
EFLOCKED File locked
EFNAME File name too long
ENOLOCK Can't create lock file
EBADMEM Can't allocate memory
EBADCOLL Bad custom collating
EBADNLS Bad NLS language

8.19.3 Errors for Remaining File Types

These error messages apply to LEVEL II indexed files and the indexed file format supported by this COBOL system, relative files, sequentia l and line sequential files. The errors are identified by the status values rather than the error number. Generally, the error number is set to zero if the call is successful, or -1 if the call fails.

If the error number is set to -1 the appropriate values are returned to the status variables: status1 and status2. There are two significant settings for status1:

Setting
Description
5 points to certain indexed errors. These are listed below.
9 points to errors for all file types including indexed.
These correspond to file status codes and are listed in the
appendix File Status Code Tables.

Errors associated with indexed files set status1 to 5, then status2 to one of the following:

 No Such Index
 Index already exists
 Prime index
 Not exclusive
 Duplicates present
 Too many keys

8.20 Migrating to Rebuild

In future releases of Object COBOL Developer Suite, the file handler utilities will be replaced by Rebuild.

Listed below are the features of the file handler utilities, together with their equivalent Rebuild options. In most cases there is a one-to-one mapping of these features.

fhinfo Replaced by rebuild -n. Rebuild gives organization, recording mode, record length, and key description whereas fhinfo gave file information and index information.
fhrebuild Replaced by rebuild filename .... This is a direct equivalent.
fhvalidate Replaced by rebuild -f. The new interface provides greater functionality. For formats 3, 4 and C-ISAM, it checks data file structure, free space list (FSL) structure, FSL entries match data file, index file structure, index and data match and checks all the keys against the data file. For other file formats, the integrity checking is on the same level as fhvalidate.
fhconvert Replaced by rebuild filename,filename.... It is a direct equivalent.
fhcreate No equivalent in Rebuild. This function enabled you to create an empty indexed file. You must write a simple COBOL program to recreate this functionality.
fhreorg Replaced by rebuild -x. This feature enables you to reorganize an indexed file on any record key. This differs from fhreorg in that fhreorg enabled you to reorganize ascending or descending.
fhedit This is replaced by the rebuild filename... command line. With the -k option you can create your own key structure as long as the key structure is wholly contained within the minimum record length.

As with the file handler utilities, Rebuild can be invoked using COBOL CALL syntax as well as from the command line. For further information on Rebuild, you should refer to the chapter Maintaining Files.


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

PreviousMaintaining Files Viewing and Editing Data FilesNext"