Initializing files

From m204wiki
Revision as of 03:47, 21 March 2013 by Alex (talk | contribs) (Automatically generated page update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Before you can use a newly created file, you must open and initialize it. Until you initialize the file, you do not have access to it; that is, you cannot define fields, store procedures, or perform any other file-level functions.

You can initialize a file on the command line, in a procedure, or using the FILEMGMT facility.

Issue the INITIALIZE command after the OPEN command:

Syntax

OPEN filename INITIALIZE

This chapter provides additional information about using INITIALIZE with already existing files, sort or hash key files, and with record security fields.

Initializing existing files

You can also use a simple INITIALIZE command on an existing file that has data already in it, for example:

OPEN CARS INITIALIZE

These commands erase all information stored in the CARS file except for the file parameter settings. All field definitions, records, and procedures are wiped out. The INITIALIZE command and the Host Language Interface IFINIT function call clear the settings in the File Control Table (FCT) and prepare it for use.

If you want to preserve the field definitions in addition to the file parameter settings, issue an INITIALIZE command with the KEEPDEFS argument, for example:

OPEN CARS INITIALIZE KEEPDEFS

Initializing sort or hash key files

To initialize a sort or hash key file (described in Sorted Files and Hash Key Files, respectively), issue the INITIALIZE command followed on the next line by SORT or HASH, along with a description of key fields.

INITIALIZE command

The syntax to initialize sort or hash key files is as follows:

Syntax

INITIALIZE [KEEPDEFS] {SORT | HASH} fieldname (attribute [,attribute...])]

where:

fieldname is the name of the sort or hash key field, followed by a list of field attributes. For example, the following commands identifies the IDENT field as having the KEY and FRV attributes:

OPEN CARS INITIALIZE SORT IDENT (KEY FRV)

Specify as many field attributes as needed. For a complete listing of field attributes, see Defining fields. The complete syntax and description of INITIALIZE is located in the Model 204 Parameter and Command Reference.

The non-resettable FPARMS parameters SORTKEY and HASHKEY are set based on the command values.

Sort and hash key file restrictions

Certain restrictions apply to the field attributes that you can specify for sort or hash key fields. Model 204 automatically supplies the following field attributes for sort key fields:

NON-CODED VISIBLE STRING

For hash key fields, Model 204 supplies the following attributes:

NON-CODED VISIBLE STRING NON-KEY

If you specify attributes that conflict with the defaults for sort or hash key fields, the INITIALIZE command is rejected.

You cannot specify the UPDATE attribute for either sort or hash key fields.

Specifying a sort or hash key for every record in a file

If a sort or hash key is required in every record-that is, if the X'02' setting was specified in the FILEORG parameter-the key can be described as:

OCCURS 1 LENGTH m

where:

If keys are not required in each record, you cannot specify the OCCURS attribute. This allows Model 204 to distinguish between a missing key and a key that has a null value. See Preallocated fields.

Initializing record security files

To initiate record security, set the X'20' option in the OPENCTL parameter in the CREATE command to indicate that record security is in effect. Record security is discussed in detail in See. The INITIALIZE command identifies the field that is to serve as the record security field. Issue the command in the form:

Syntax

INITIALIZE RECSCTY fieldname (attribute [,attribute...])]

where:

fieldname is the name of the record security field, followed by a list of field attributes. Specify as many field attributes as are needed. For a complete listing of field attributes, see Defining fields.

The non-resettable FPARMS parameter RECSTY is set based on the command values.

Examples

INITIALIZE RECSCTY PROTECT (ORD CHAR)

The RECSCTY clause can be preceded or followed by the description of the sort or hash key presented in the preceding section. For example:

INITIALIZE SORT ID (KEY,FRV) RECSCTY SECRET

All record security fields must have an indexed attribute (ORDERED or KEY). Although the NON-KEY attribute is the normal default, Model 204 automatically supplies KEY as the default for all record security fields. If you specify NON-KEY in a record security field description, the INITIALIZE command is rejected.

Specifying LENGTH on record security fields

If the record security field is defined with the option:

LENGTH m

then ensure that the value of m is larger than the length allowed for LOGIN accounts (see Chapter 18). Otherwise, if a user who has a long user ID attempts to store a record, Model 204 stores an empty record and cancels the user's request. The record is then inaccessible.