Initializing files: Difference between revisions
No edit summary |
|||
Line 6: | Line 6: | ||
<p class="code">OPEN <var class="term">filename</var> | <p class="code">OPEN <var class="term">filename</var> | ||
<var class="term">password</var> with necessary privileges if file is not public | <var class="term">password</var> with necessary privileges if file is not public | ||
IN <var class="term">filename</var> INITIALIZE | IN <var class="term">filename</var> INITIALIZE | ||
</p> | </p> | ||
<p>This topic provides additional information about using INITIALIZE with already existing files, sort or hash key files, and with record security fields.</p> | <p>This topic provides additional information about using INITIALIZE with already existing files, sort or hash key files, and with record security fields.</p> | ||
====Always use the IN filename clause==== | ====Always use the IN filename clause==== | ||
The above syntax shows the <var>[[IN clause in a command|IN]]</var> <var class="term">filename</var> clause before the <var>INITIALIZE</var> command. Although this is, strictly speaking, an optional clause, its use is strongly recommended. Without it, the default file is initialized, and sometimes the default file context, due to <var>OPEN</var> errors or other circumstances, is not the file which should be initialized. This can result in severe unintentional effects, and can be avoided by <b>always</b> specifying the <var>IN</var> <var class="term">filename</var> clause. | The above syntax shows the <var>[[IN clause in a command|IN]]</var> <var class="term">filename</var> clause before the <var>INITIALIZE</var> command. Although this is, strictly speaking, an optional clause, its use is strongly recommended. Without it, the default file is initialized, and sometimes the default file context, due to <var>OPEN</var> errors or other circumstances, is not the file which should be initialized. This can result in severe unintentional effects, and can be avoided by <b>always</b> specifying the <var>IN</var> <var class="term">filename</var> clause. | ||
The rest of the syntax or examples of the <var>INITIALIZE</var> command on this page include the <var>IN</var> clause, to reinforce this recommendation. | The rest of the syntax or examples of the <var>INITIALIZE</var> command on this page include the <var>IN</var> clause, to reinforce this recommendation. | ||
==Initializing existing files== | ==Initializing existing files== | ||
<p>You can also use a simple INITIALIZE command on an existing file that has data already in it, for example:</p> | <p>You can also use a simple INITIALIZE command on an existing file that has data already in it, for example:</p> | ||
<p class="code">OPEN CARS | <p class="code">OPEN CARS | ||
<var class="term">password with necessary privileges if file is not public | <var class="term">password</var> with necessary privileges if file is not public | ||
INITIALIZE | IN CARS INITIALIZE | ||
</p> | </p> | ||
<p>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. </p> | <p>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. </p> | ||
Line 24: | Line 24: | ||
<p class="code">OPEN CARS | <p class="code">OPEN CARS | ||
<var class="term">password with necessary privileges if file is not public</var> | <var class="term">password with necessary privileges if file is not public</var> | ||
INITIALIZE KEEPDEFS | IN CARS INITIALIZE KEEPDEFS | ||
</p> | </p> | ||
==Initializing sort or hash key files== | ==Initializing sort or hash key files== | ||
<p>To initialize a sort or hash key file (described in [[ Sorted Files#Sorted Files|Sorted Files]] and [[ Hash Key Files#Hash Key Files|Hash Key Files]], respectively), issue the INITIALIZE command followed on the next line by SORT or HASH, along with a description of key fields.</p> | <p>To initialize a sort or hash key file (described in [[ Sorted Files#Sorted Files|Sorted Files]] and [[ Hash Key Files#Hash Key Files|Hash Key Files]], respectively), issue the INITIALIZE command followed on the next line by SORT or HASH, along with a description of key fields.</p> | ||
Line 38: | Line 38: | ||
<p><var class="term">fieldname</var> 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:</p> | <p><var class="term">fieldname</var> 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:</p> | ||
<p class="code">OPEN CARS | <p class="code">OPEN CARS | ||
INITIALIZE | IN <var class="term">filename</var> INITIALIZE | ||
SORT IDENT (KEY FRV) | SORT IDENT (KEY FRV) | ||
</p> | </p> | ||
<p>Specify as many field attributes as needed. For a complete listing of field attributes, see [[ Defining Fields Manually#Defining fields|Defining fields]]. The complete syntax and description of INITIALIZE is located on the [[INITIALIZE command]] page.</p> | <p>Specify as many field attributes as needed. For a complete listing of field attributes, see [[ Defining Fields Manually#Defining fields|Defining fields]]. The complete syntax and description of INITIALIZE is located on the [[INITIALIZE command]] page.</p> | ||
<p>The non-resettable [[FPARMS_and_TABLES_File_Parameters#File_characteristics_parameters_.28FPARMS.29|FPARMS]] parameters [[SORTKEY_parameter|SORTKEY]] and [[HASHKEY_parameter|HASHKEY]] are set based on the command values.</p> | <p>The non-resettable [[FPARMS_and_TABLES_File_Parameters#File_characteristics_parameters_.28FPARMS.29|FPARMS]] parameters [[SORTKEY_parameter|SORTKEY]] and [[HASHKEY_parameter|HASHKEY]] are set based on the command values.</p> | ||
===Sort and hash key file restrictions=== | ===Sort and hash key file restrictions=== | ||
<p>Certain restrictions apply to the field attributes that you can specify for sort or hash key fields. <var class="product">Model 204</var> automatically supplies the following field attributes for sort key fields:</p> | <p>Certain restrictions apply to the field attributes that you can specify for sort or hash key fields. <var class="product">Model 204</var> automatically supplies the following field attributes for sort key fields:</p> | ||
<p class="code">NON-CODED VISIBLE STRING | <p class="code">NON-CODED VISIBLE STRING | ||
</p> | </p> | ||
<p>For hash key fields, <var class="product">Model 204</var> supplies the following attributes:</p> | <p>For hash key fields, <var class="product">Model 204</var> supplies the following attributes:</p> | ||
<p class="code">NON-CODED VISIBLE STRING NON-KEY | <p class="code">NON-CODED VISIBLE STRING NON-KEY | ||
</p> | </p> | ||
<p>If you specify attributes that conflict with the defaults for sort or hash key fields, the INITIALIZE command is rejected.</p> | <p>If you specify attributes that conflict with the defaults for sort or hash key fields, the INITIALIZE command is rejected.</p> | ||
Line 55: | Line 55: | ||
===Specifying a sort or hash key for every record in a file=== | ===Specifying a sort or hash key for every record in a file=== | ||
<p>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:</p> | <p>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:</p> | ||
<p class="code">OCCURS <var class="term">n</var> LENGTH <var class="term">m</var> | <p class="code">OCCURS <var class="term">n</var> LENGTH <var class="term">m</var> | ||
</p> | </p> | ||
<p>where:</p> | <p>where:</p> | ||
Line 64: | Line 64: | ||
For more information, see [[ Defining Fields Manually#OCCURS and LENGTH clauses|OCCURS and LENGTH clauses]]. | For more information, see [[ Defining Fields Manually#OCCURS and LENGTH clauses|OCCURS and LENGTH clauses]]. | ||
<p>If keys are not required in each record, you cannot specify the OCCURS attribute. This allows <var class="product">Model 204</var> to distinguish between a missing key and a key that has a null value. See [[ Field Design (File Management)#Preallocated fields|Preallocated fields]] for more information.</p> | <p>If keys are not required in each record, you cannot specify the OCCURS attribute. This allows <var class="product">Model 204</var> to distinguish between a missing key and a key that has a null value. See [[ Field Design (File Management)#Preallocated fields|Preallocated fields]] for more information.</p> | ||
==Initializing record security files== | ==Initializing record security files== | ||
<p>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 <b>See</b>. The INITIALIZE command identifies the field that is to serve as the record security field. Issue the command in the form:</p> | <p>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 <b>See</b>. The INITIALIZE command identifies the field that is to serve as the record security field. Issue the command in the form:</p> | ||
====Syntax==== | ====Syntax==== | ||
<p class="code">INITIALIZE | <p class="code"><var>IN</var> <var class="term">filename</var> INITIALIZE | ||
RECSCTY fieldname (attribute [,attribute...])] | RECSCTY fieldname (attribute [,attribute...])] | ||
</p> | </p> | ||
<p>where:</p> | <p>where:</p> | ||
Line 75: | Line 75: | ||
<p>The non-resettable FPARMS parameter RECSTY is set based on the command values.</p> | <p>The non-resettable FPARMS parameter RECSTY is set based on the command values.</p> | ||
====Examples==== | ====Examples==== | ||
<p class="code">INITIALIZE | <p class="code">IN filename INITIALIZE | ||
RECSCTY PROTECT (ORD CHAR) | RECSCTY PROTECT (ORD CHAR) | ||
</p> | </p> | ||
<p>The RECSCTY clause can be preceded or followed by the description of the sort or hash key presented in the preceding section. For example:</p> | <p>The RECSCTY clause can be preceded or followed by the description of the sort or hash key presented in the preceding section. For example:</p> | ||
<p class="code">INITIALIZE | <p class="code">IN filename INITIALIZE | ||
SORT ID (KEY,FRV) | SORT ID (KEY,FRV) | ||
RECSCTY SECRET | RECSCTY SECRET | ||
Line 91: | Line 90: | ||
<p>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, <var class="product">Model 204</var> stores an empty record and cancels the user's request. The record is then inaccessible.</p> | <p>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, <var class="product">Model 204</var> stores an empty record and cancels the user's request. The record is then inaccessible.</p> | ||
<p> </p> | <p> </p> | ||
[[Category:File management]] | [[Category:File management]] |
Revision as of 16:00, 15 October 2013
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 subsystem facility.
For an un-initialized file, issue the INITIALIZE command after the OPEN command:
Syntax
OPEN filename password with necessary privileges if file is not public IN filename INITIALIZE
This topic provides additional information about using INITIALIZE with already existing files, sort or hash key files, and with record security fields.
Always use the IN filename clause
The above syntax shows the IN filename clause before the INITIALIZE command. Although this is, strictly speaking, an optional clause, its use is strongly recommended. Without it, the default file is initialized, and sometimes the default file context, due to OPEN errors or other circumstances, is not the file which should be initialized. This can result in severe unintentional effects, and can be avoided by always specifying the IN filename clause.
The rest of the syntax or examples of the INITIALIZE command on this page include the IN clause, to reinforce this recommendation.
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 password with necessary privileges if file is not public IN 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 password with necessary privileges if file is not public IN 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 IN filename 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 on the INITIALIZE command page.
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 n LENGTH m
where:
- OCCURS n specifies the number of occurrences of the field that are preallocated or reserved in each Table B record.
- LENGTH m specifies the length of NON-CODED STRING and FLOAT fields.
For more information, see OCCURS and LENGTH clauses.
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 for more information.
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
IN filename 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
IN filename 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:
IN filename 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.