Introduction

Language Structure

IB Statements

File System

Comet 32 Runtime

Index

CREATE Key statement

For a discussion about using sub keys in programs go here: Keyed files
Syntax: CREATEKEY filename, Key-name,key-size,key-position ,DIR=directory [,EXCP=statement-label | NOEXCP]

Discussion: The CREATEKEY statement creates a new sub key for a specified keyed file on a specified Comet directory.

The filename parameter is the name of the file for which the sub key is to be created. It can be a string constant or a string variable, with a length up to eight characters. The file must exist (have been created), and must be empty.

The Key-name parameter is an abstract way to designate which sub key to use when OPENing the file. The name can be a string constant or a string variable, with a maximum length of 64 alpha-numeric characters. Comet will strip blanks and convert any alpha characters to upper case. The KEYSTAT function will return this converted name.

The key-size parameter, defines the number of characters in the sub key (index). A maximum of 254 characters is allowed.

The key-position indicates the byte position in the record. In these files, CFAM automatically stores a copy of the key data in your record. This helps to insure integrity between the key tree and the record set and makes rebuilding the key tree a snap in the event a recovery is required.

The directory parameter is the name of the Comet directory where the file has been created. The directory can be a string constant or a string variable, with a maximum length of three characters.

Example 1:
CREATEKEY "CUSTNAME","Last Name",35,0,DIR="DSK",EXCP=9999
In this example, the CREATEKEY statement is used to create a sub key for the file called CUSTNAME on Comet directory DSK. The sub key will start at the first location in the record and it will be 35 bytes long.

If an exception occurs when this statement is executed (e.g., if the file has records in it), the program will branch to statement- label 9999.

Example 2:
Length 8 & Local Filename$
Length 3 & Local Dirname$
Length 5 & local CustId$
LENGTH 10 & LOCAL FirstName$ LastName$ Name$
Cust: Format FirstName$; LastName$
.
.
.
Print "Enter The File Name:"
Input Filename$
Print "Enter The Directory Name:"
Input Dirname$
Create Filename$,256,K,5,20,Dir=Dirname$,Excp=8000
CreateKey Filename$, "First",10,0,Dir=Dirname$
CreateKey Filename$, "Last",10,10,Dir=Dirname$
.
.
.
close(98) & open(98) Filename$, key="first"
.
.
print 'Enter a first name for search'
input Name$
position(98)key=Name$
do while sub(key(98),1,len(Name$)) = Name$
   read(98,Cust)
   print fname$;Lname$
loop
done:
.
.

In this example, the user is prompted for the filename and Comet directory name (defined at the beginning of this program segment). The CREATE statement then creates a file by the name entered by the user (on the directory entered by the user). The file will be created with a record size of 256 and a key size of 5. The Primary Key will consist of the Customer ID.

Then two secondary keys will be created for the file. One Named FIRST and another Named LAST.

Later, the user is prompted for a first name. The program will list all records whose first name matches the name entered

If an exception occurs when this statement is executed (e.g., if the file already exists), the program will branch to statement- label 8000.