Initializing files: Difference between revisions
m (Dme moved page Initializing Files to Initializing files) |
(Automatically generated page update) |
||
(18 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
==Overview== | ==Overview== | ||
<p>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.</p> | <p> | ||
<p>You can initialize a file on the command line, in a procedure, or using the [[ | 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.</p> | ||
<p>For an un-initialized file, issue the [[INITIALIZE command]] after the OPEN command:</p> | <p> | ||
You can initialize a file on the command line, in a procedure, or using the [[FILEMGMT overview|FILEMGMT]] subsystem facility. </p> | |||
<p> | |||
For an un-initialized file, issue the <var>[[INITIALIZE command|INITIALIZE]]</var> command after the <var>OPEN</var> command:</p> | |||
====Syntax==== | ====Syntax==== | ||
<p class=" | <p class="syntax">OPEN <span class="term">filename</span> | ||
< | <span class="term">password</span> with necessary privileges if file is not public | ||
IN < | IN <span class="term">filename</span> 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 <var>INITIALIZE</var> 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 | The above syntax shows the <var>[[Overview of Model 204 commands#IN: Specifying an 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 (that was most recently opened) is initialized, and sometimes the default file context is not the file which is intended to be initialized. This can result in severe unintentional effects; for example: | ||
<p class="code">* This example is <b>not</b> the recommended approach | |||
<nowiki>OPEN FILEA | |||
*passwdA | |||
OPEN FILEZ | |||
*passwdB | |||
INITIALIZE | |||
</nowiki></p> | |||
In the above, if an error occurs on <code>OPEN FILEZ</code> (for example, a file enqueueing conflict), the default file is <code>FILEA</code> and so that file is initialized, deleting all of its contents. The much better approach would have been <code>IN FILEZ INITIALIZE</code>. | |||
Problems such as this can be avoided by <b>always</b> specifying the <var>IN</var> <var class="term">filename</var> clause on the <var>INITIALIZE</var> command. | |||
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</var> with necessary privileges if file is not public | <var class="term">password</var> with necessary privileges if file is not public | ||
IN CARS 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> | ||
<p>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:</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 <var>INITIALIZE</var> command and the Host Language Interface <var>IFINIT</var> function call clear the settings in the File Control Table (FCT) and prepare it for use. </p> | ||
===Keeping field definitions=== | |||
<p> | |||
If you want to preserve the field definitions in addition to the file parameter settings, issue an <var>INITIALIZE</var> command with the <var>KEEPDEFS</var> argument, 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> | <var class="term">password with necessary privileges if file is not public</var> | ||
IN CARS 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 | <p> | ||
To initialize a sort or hash key file (described in [[Sorted files]] and [[Hash key files]], respectively), issue the <var>INITIALIZE</var> command followed on the next line by <var>SORT</var> or <var>HASH</var>, along with a description of key fields.</p> | |||
<p class="note"><b>Note:</b> Do not use the DEFINE command to define sort key or hash key fields.</p> | |||
===INITIALIZE command=== | ===INITIALIZE command=== | ||
<p>The syntax to initialize sort or hash key files is as follows:</p> | <p> | ||
The syntax to initialize sort or hash key files is as follows:</p> | |||
<p class=" | |||
{SORT | HASH} < | <p class="syntax">INITIALIZE [KEEPDEFS] | ||
{SORT | HASH} <span class="term">fieldname</span> (<span class="term">attribute</span> [,<span class="term">attribute</span>...])] | |||
</p> | </p> | ||
<p> | <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 | Where:</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 identify the <code>IDENT</code> field as having the <var>KEY</var> and <var>FRV</var> attributes:</p> | |||
<p class="code">OPEN CARS | <p class="code">OPEN CARS | ||
IN <var class="term">filename</var> 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 | <p> | ||
<p>The non-resettable [[ | 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 <var>INITIALIZE</var> is located on the [[INITIALIZE command]] page.</p> | ||
<p> | |||
The non-resettable [[FPARMS and TABLES file parameters#File characteristics parameters (FPARMS)|FPARMS]] parameters <var>[[SORTKEY_parameter|SORTKEY]]</var> and <var>[[HASHKEY_parameter|HASHKEY]]</var> 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> | ||
<p>You cannot specify the UPDATE attribute for either sort or hash key fields.</p> | If you specify attributes that conflict with the defaults for sort or hash key fields, the <var>INITIALIZE</var> command is rejected.</p> | ||
<p> | |||
You cannot specify the <var>UPDATE</var> attribute for either sort or hash key fields.</p> | |||
===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> | ||
<p class=" | If a sort or hash key is required in every record (that is, if the X'02' setting was specified in the <var>FILEORG</var> parameter), the key can be described as:</p> | ||
<p class="syntax">OCCURS <span class="term">n</span> LENGTH <span class="term">m</span> | |||
</p> | </p> | ||
<p> | <p>Where:</p> | ||
<ul> | <ul> | ||
<li>OCCURS <var class="term">n</var> specifies the number of occurrences of the field that are preallocated or reserved in each Table B record. </li> | <li><var>OCCURS</var> <var class="term">n</var> specifies the number of occurrences of the field that are preallocated or reserved in each Table B record. </li> | ||
<li>LENGTH <var class="term">m</var> specifies the length of NON-CODED STRING and FLOAT fields. </li> | |||
<li><var>LENGTH</var> <var class="term">m</var> specifies the length of <var>NON-CODED</var> <var>STRING</var> and <var>FLOAT</var> fields. </li> | |||
</ul> | </ul> | ||
For more information, see [[ Defining | |||
<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 | 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 <var>OCCURS</var> 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#Preallocated fields (OCCURS attribute)|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 < | <p> | ||
To initiate record security, set the X'20' option in the <var>OPENCTL</var> parameter in the <var>CREATE</var> command to indicate that record security is in effect. Record security is discussed in detail in [[Model 204 security features#Record security|Record security]]. The <var>INITIALIZE</var> command identifies the field that is to serve as the record security field. </p> | |||
<p class="note"><b>Note:</b> Do not use the DEFINE command to define record security fields.</p> | |||
====Syntax==== | ====Syntax==== | ||
<p class=" | Issue the command in this form: | ||
RECSCTY fieldname (attribute [,attribute...])] | |||
<p class="syntax">IN <span class="term">filename</span> INITIALIZE | |||
RECSCTY <span class="term">fieldname</span> (<span class="term">attribute</span> [,<span class="term">attribute</span>...])] | |||
</p> | </p> | ||
<p> | <p>Where:</p> | ||
<p>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 | <p><var class="term">fieldname</var> 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 manually#Defining fields|Defining fields]].</p> | ||
<p>The non-resettable FPARMS parameter RECSTY is set based on the command values.</p> | <p> | ||
The non-resettable FPARMS parameter <var>RECSTY</var> is set based on the command values.</p> | |||
====Examples==== | ====Examples==== | ||
<p class="code">IN filename INITIALIZE | <p class="code">IN <i>filename</i> 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> | ||
<p class="code">IN filename INITIALIZE | The <var>RECSCTY</var> 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">IN <i>filename</i> INITIALIZE | |||
SORT ID (KEY,FRV) | SORT ID (KEY,FRV) | ||
RECSCTY SECRET | RECSCTY SECRET | ||
</p> | </p> | ||
<p>All record security fields must have an indexed attribute (ORDERED or KEY). Although the NON-KEY attribute is the normal default, <var class="product">Model 204</var> 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.</p> | <p> | ||
All record security fields must have an indexed attribute (<var>ORDERED</var> or <var>KEY</var>). Although the <var>NON-KEY</var> attribute is the normal default, <var class="product">Model 204</var> automatically supplies <var>KEY</var> as the default for all record security fields. If you specify <var>NON-KEY</var> in a record security field description, the <var>INITIALIZE</var> command is rejected.</p> | |||
===Specifying LENGTH on record security fields=== | ===Specifying LENGTH on record security fields=== | ||
<p>If the record security field is defined with the option:</p> | <p> | ||
If the record security field is defined with the <var>LENGTH</var> option:</p> | |||
<p class="code">LENGTH <var class="term">m</var> | <p class="code">LENGTH <var class="term">m</var> | ||
</p> | </p> | ||
<p> | <p> | ||
Ensure that the value of <var class="term">m</var> is larger than the length allowed for <var>LOGIN</var> accounts (see [[Model 204 security features#Record security|Record security]]). 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> | |||
[[Category: | [[Category:Model 204 files]] |
Latest revision as of 21:17, 7 April 2017
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 (that was most recently opened) is initialized, and sometimes the default file context is not the file which is intended to be initialized. This can result in severe unintentional effects; for example:
* This example is not the recommended approach OPEN FILEA *passwdA OPEN FILEZ *passwdB INITIALIZE
In the above, if an error occurs on OPEN FILEZ
(for example, a file enqueueing conflict), the default file is FILEA
and so that file is initialized, deleting all of its contents. The much better approach would have been IN FILEZ INITIALIZE
.
Problems such as this can be avoided by always specifying the IN filename clause on the INITIALIZE command.
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.
Keeping field definitions
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.
Note: Do not use the DEFINE command to define sort key or hash key fields.
INITIALIZE command
The syntax to initialize sort or hash key files is as follows:
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 identify 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 Record security. The INITIALIZE command identifies the field that is to serve as the record security field.
Note: Do not use the DEFINE command to define record security fields.
Syntax
Issue the command in this form:
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 LENGTH option:
LENGTH m
Ensure that the value of m is larger than the length allowed for LOGIN accounts (see Record security). 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.