Defining fields manually: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (link repair)
 
(25 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<p>This chapter describes the use of [[DEFINE FIELD command]], which allows you to define the fields in a file. For the full syntax, follow that link.</p>
<p>
This chapter describes the use of the <var>[[DEFINE FIELD command|DEFINE FIELD]]</var> command, which allows you to define the fields in a file. For the full syntax, follow that link.</p>
==Defining fields==
==Defining fields==
<p>After you [[CREATE command|create]] and [[INITIALIZE command|initialize]] a <var class="product">Model&nbsp;204</var> file, use the DEFINE command or the IFDFLD Host Language Interface function to establish the names and types of the fields in the file. </p>
<p>
<p>The format of the DEFINE command is:</p>
After you <var>[[CREATE command: File|CREATE]]</var> and <var>[[INITIALIZE command|INITIALIZE]]</var> a <var class="product">Model&nbsp;204</var> file, use the DEFINE command or the IFDFLD Host Language Interface function to establish the names and types of the fields in the file. </p>
 
<b>Syntax</b>
<b>Syntax</b>
<p>
The format of the DEFINE command is:</p>
<p class="code">DEFINE FIELD <var class="term">name</var> [(<var class="term">attribute</var> [,[<var class="term">attribute</var> ...]]) |
<p class="code">DEFINE FIELD <var class="term">name</var> [(<var class="term">attribute</var> [,[<var class="term">attribute</var> ...]]) |
   WITH [<var class="term">attribute</var>][,[<var class="term">attribute</var> ...]]]
   WITH [<var class="term">attribute</var>][,[<var class="term">attribute</var> ...]]]
</p>
</p>
<p>where:</p>
<p>
<p>name is a 1 to 255 character name that must begin with a letter and can contain any alphanumeric characters, including spaces, except:</p>
where:</p>
<p class="code"> ??
<ul>
<li><var class="term">name</var> is a 1 to 255 character name that must begin with a letter and can contain any alphanumeric characters, including spaces, except:
<p class="code"><b>??
?$
?$
?&amp;
?&amp;
@ (or an alternative delete character)
@</b> (or an alternative delete character)
<b></b># (or an alternative flush character)
<b>#</b> (or an alternative flush character)
;
<b>;</b>
</p>
</p></li>
<p>attribute is a member of the list in [[Field attributes|Field attributes]].     </p>
 
<p>If you specify the ORDERED attribute, you can follow it with a list of qualifying parameters that designate the type of ordering and the space utilization characteristics of the Ordered Index. See the discussion of the ORDERED attribute in [[ Field Descriptions and Attributes#ORDERED and NON-ORDERED attributes|ORDERED and NON-ORDERED attributes]].  </p>
<li><var class="term">attribute</var> is a member of the list in [[Field attributes]].  
<p>
If you specify the ORDERED attribute, you can follow it with a list of qualifying parameters that designate the type of ordering and the space utilization characteristics of the Ordered Index. See the discussion of the ORDERED attribute in [[ Field design#ORDERED and NON-ORDERED attributes|ORDERED and NON-ORDERED attributes]].  </p></li>
</ul>
 
<b>Example</b>
<b>Example</b>
<p>In the following example the field CUSTID is named and given the ORDERED CHARACTER attribute:</p>
<p>
In the following example, the field CUSTID is named and given the ORDERED CHARACTER attribute:</p>
<p class="code">DEFINE FIELD CUSTID ORDERED CHARACTER
<p class="code">DEFINE FIELD CUSTID ORDERED CHARACTER
</p>
</p>
<p>Specify as many field attributes as needed from [[Field attributes|Field attributes]]. For each attribute pair shown in the list, only one of the alternatives can be specified; conflicting attributes, such as KEY and NON-KEY, cannot be used together in a single description.</p>
<p>
<p>Note</p>
Specify as many field attributes as needed from [[Field attributes]]. For each attribute pair shown in the list, only one of the alternatives can be specified; conflicting attributes, such as KEY and NON-KEY, cannot be used together in a single description.</p>
<p>Every attribute has a default value. Therefore, you only need to specify the attribute if it is not the default.</p>
<p class="note"><b>Note:</b>
Every attribute has a default value. Therefore, you only need to specify the attribute if it is not the default.</p>
===When to use the FIELD keyword===
===When to use the FIELD keyword===
<p>The keyword FIELD is required before field names that begin with the word FIELD, PRINTER, or DATASET. It is optional with other field names. If FIELD is specified, only one field can be defined or redefined per command. For example:</p>
<p>
The keyword FIELD is required before field names that begin with the word FIELD, PRINTER, or DATASET. It is optional with other field names. If FIELD is specified, only one field can be defined or redefined per command. For example:</p>
<p class="code">DEFINE FIELD POLICYHOLDER
<p class="code">DEFINE FIELD POLICYHOLDER
DEFINE POLICYHOLDER
DEFINE POLICYHOLDER
</p>
</p>
<p>Each example above defines a field with the name POLICYHOLDER. The following example defines a field with the name FIELD LOCATION:</p>
<p>
Each example above defines a field with the name POLICYHOLDER. The following example defines a field with the name FIELD LOCATION:</p>
<p class="code">DEFINE FIELD FIELD LOCATION
<p class="code">DEFINE FIELD FIELD LOCATION
</p>
</p>
===Defining sort key, hash key, and record security fields===
===Defining sort key, hash key, and record security fields===
<p>The DEFINE command cannot be used to define sort key fields, hash key fields, or record security fields. These fields can be defined only with the INITIALIZE command, described in [[ Initializing Files#INITIALIZE command|INITIALIZE command]], and the appropriate parameter settings.</p>
<p>
The DEFINE command cannot be used to define sort key fields, hash key fields, or record security fields. These fields can be defined only with the <var>[[INITIALIZE command|INITIALIZE]]</var> command and the appropriate parameter settings.</p>
===Field attributes===
===Field attributes===
<p>The attributes listed in the following tables are introduced in [[Field Design (File Management)|Field Design]], along with a summary of the rules follow in assigning them. A number of the attributes have additional optional attributes (in particular, see [[Field Design (File Management)#ORDERED field definition|the ORDERED attribute]]) that can be specified with the [[DEFINE FIELD command]], which are also described in [[Field Design (File Management)|Field Design]].</p>
<p>
 
The attributes listed in the following tables are introduced in [[Field design|Field design]], along with a summary of the rules follow in assigning them. A number of the attributes have additional optional attributes (in particular, see [[Field design#ORDERED field definition|the ORDERED attribute]]) that can be specified with the [[DEFINE FIELD command]], which are also described in [[Field design|Field design]].</p>
 
====Indexing attributes====
====Indexing attributes====
 
<p>
<p>The overall effect of the defaults is that, unless specified, the field is not indexed.</p>  
The overall effect of the defaults is that, unless specified, the field is not indexed.</p>
 
<table>
<table>
<caption>Indexing field attributes with the DEFINE command</caption>
<caption>Indexing field attributes with the DEFINE command</caption>
<tr class="head">
<tr class="head">
<th>Attribute</th>
<th>Attribute</th><th>Abbreviation</th><th>Default</th>
<th>Abbreviation</th>
<th>Default</th>
</tr>
</tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>ORDERED CHARACTER</p>
ORDERED CHARACTER<p>NON-ORDERED</p>
<p>NON-ORDERED</p>
</td>
</td>
<td rowspan="2">
<td>
<p>ORD CHAR</p>
ORD CHAR<p>NORD</p>
<p>NORD</p>
</td>
</td>
<td rowspan="2">NON-ORDERED</td>
<td>NON-ORDERED</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
ORDERED NUMERIC<p>NON-ORDERED</p>
<td rowspan="2">
<p>ORDERED NUMERIC</p>
<p>NON-ORDERED</p>
</td>
</td>
<td rowspan="2">
<td>
<p>ORD NUM</p>
ORD NUM<p>NORD</p>
<p>NORD</p>
</td>
</td>
<td rowspan="2">NON-ORDERED</td>
<td>NON-ORDERED</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
KEY<p>NON-KEY</p>
<td rowspan="2">
<p>KEY</p>
<p>NON-KEY</p>
</td>
</td>
<td rowspan="2">
<td>&nbsp;
<p>-</p>
<p>NKEY</p>
<p>NKEY</p>
</td>
</td>
<td rowspan="2">NON-KEY</td>
<td>NON-KEY</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
FRV<p>NON-FRV</p>
<td rowspan="2">
<p>The ORD attribute is preferable; shown for compatibility.</p>
<p><var>FRV</var></p>
<p><var>NON-FRV</var></p>
<p><var>The ORD attribute is preferable; shown for compatibility. </var></p>
</td>
</td>
<td rowspan="2">
<td>&nbsp;
<p><var>-</var></p>
<p>NFRV</p>
<p><var>NFRV</var></p>
</td>
</td>
<td rowspan="2"><var>NON-FRV</var></td>
<td>NON-FRV</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
[NUMERIC] RANGE<p>NON-RANGE</p>
<td rowspan="2">
<p>Obsolete; supported for compatibility.</p>
<p><var>[NUMERIC] RANGE</var></p>
<p><var>NON-RANGE</var></p>
<p><var>Obsolete; supported for compatibility. </var></p>
</td>
</td>
<td rowspan="2">
<td>
<p><var>NR</var></p>
NR<p>NNR</p>
<p><var>NNR</var></p>
</td>
</td>
<td rowspan="2"><var>NON-RANGE</var></td>
<td>NON-RANGE</td>
</tr>
<tr>
</tr>
</tr>
</table>
</table>
 
====Data types====
====Data types====
 
<p>
<p>In most cases, only one of these may be specified on any field (see the UTF attributes). The default is STRING</p>
In most cases, only one of these may be specified on any field (see the UTF attributes). The default is STRING</p>
 
 
<table>
<table>
<caption>Data type attributes with the DEFINE command</caption>
<caption>Data type attributes with the DEFINE command</caption>
Line 131: Line 132:
<th>Notes</th>
<th>Notes</th>
</tr>
</tr>
<tr>
<tr>
<td>STRING</td>
<td>STRING</td>
Line 136: Line 138:
<td></td>
<td></td>
</tr>
</tr>
<tr>
<tr>
<td>BINARY</td>
<td>BINARY</td>
Line 141: Line 144:
<td></td>
<td></td>
</tr>
</tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>BINARY-LARGE-OBJECT</p>
BINARY-LARGE-OBJECT<p>CHARACTER-LARGE-OBJECT</p>
<p>CHARACTER-LARGE-OBJECT</p>
</td>
</td>
<td rowspan="2">
<td>
<p>BLOB</p>
BLOB<p>CLOB</p>
<p>CLOB</p>
</td>
</td>
<td rowspan="2">
<td>
<p>must have Table E enabled</p>
Must have Table E enabled<p></p>
<p></p>
</td>
</td>
</tr>
</tr>
<tr></tr>
<tr>
<tr>
<td>FLOAT</td>
<td>FLOAT</td>
<td>FLT</td>
<td>FLT</td>
<td>must have LEN specified</td>
<td>Must have LEN specified</td>
</tr>
</tr>
<tr>
<tr>
<td>DATETIME</td>
<td>DATETIME</td>
Line 166: Line 168:
<td></td>
<td></td>
</tr>
</tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>UTF-8</p>
UTF-8<p>UTF-16</p>
<p>UTF-16</p>
</td>
</td>
<td rowspan="2">
<td>
<p>UTF8</p>
UTF8<p>UTF16</p>
<p>UTF16</p>
</td>
</td>
<td rowspan="2">
<td>
<p>Must be used in conjunction with the BLOB or CLOB attribute</p>  
Must be used in conjunction with the BLOB or CLOB attribute<p></p>
</td>
</td>
</tr>
</tr>
<tr></tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>VISIBLE</p>
VISIBLE<p>INVISIBLE</p>
<p>INVISIBLE</p>
</td>
</td>
<td rowspan="2">
<td>
<p>VIS</p>
VIS<p>INV</p>
<p>INV</p>
</td>
</td>
<td rowspan="2"></td>
</tr>
<tr>
</tr>
<tr>
</tr>
</tr>
</table>
</table>
 
==== Data Content Attributes====
==== Data content attributes====
 
<table>
<table>
<caption>Data content field attributes with the DEFINE command</caption>
<caption>Data content field attributes with the DEFINE command</caption>
Line 206: Line 199:
<th>Default</th>
<th>Default</th>
</tr>
</tr>
<tr>
<td rowspan="2">
<p>UPDATE IN PLACE</p>
<p>UPDATE AT END</p>
</td>
<td rowspan="2">
<p>UP</p>
<p>UE</p>
</td>
<td rowspan="2">UPDATE IN PLACE</td>
</tr>
<tr>
</tr>
<tr>
<tr>
<td>
<td>
<p>LENGTH <var class="term">m</var></p>
LENGTH <var class="term">m</var>
</td>
</td>
<td>
<td>
<p>LEN <var class="term">m</var></p>
LEN <var class="term">m</var>
</td>
</td>
<td>
<td>
<p>No preallocated length</p>
No preallocated length
</td>
</td>
</tr>
</tr>
<tr>
</tr>
<tr>
<tr>
<td>OCCURS n</td>
<td>OCCURS n</td>
Line 237: Line 217:
<td>No preallocated occurrences</td>
<td>No preallocated occurrences</td>
</tr>
</tr>
<tr>
</tr>
<tr>
<tr>
<td>
<td>
<p>PAD <var class="term">character</var></p>
PAD <var class="term">character</var>
</td>
</td>
<td>
<td>
<p></p>
&nbsp;
</td>
</td>
<td>
<td>
<p>Character = X'00'</p>
<var class="term">character</var> = X'00'
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>
DEFERRABLE<p>NON-DEFERRABLE</p>
</td>
<td>
DEF<p>NDEF</p>
</td>
<td>DEFERRABLE</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
UPDATE IN PLACE<p>UPDATE AT END</p>
<td rowspan="2">
<p>DEFERRABLE</p>
<p>NON-DEFERRABLE</p>
</td>
</td>
<td rowspan="2">
<td>
<p>DEF</p>
UP<p>UE</p>
<p>NDEF</p>
</td>
</td>
<td rowspan="2">DEFERRABLE</td>
<td>UPDATE IN PLACE</td>
</tr>
</tr>
<tr>
<tr>
<td>DEFAULT-VALUE
<p>STORE-DEFAULT</p>
<p>STORE-NULL</p></td>
<td>DV
<p>SD</p>
<p>SN</p></td>
<td>&nbsp;
<p>LITERAL</p>
<p>LITERAL</p></td>
</tr>
</tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>AT-MOST-ONE</p>
AT-MOST-ONE<p>EXACTLY-ONE</p>
<p>EXACTLY-ONE</p>
<p>REPEATABLE</p>
<p>REPEATABLE</p>
</td>
</td>
<td rowspan="2">
<td>
<p>ONE</p>
ONE<p>EXONE</p>
<p>EXONE</p>
<p>REPT</p>
<p>REPT</p>
</td>
</td>
<td rowspan="2">REPT (except in 1NF files), or inside an RFG (where it is EXONE)</td>
<td>REPT (except in 1NF files), or inside a field group (where it is EXONE)<p></p><p></p></td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
CODED<p>NON-CODED</p>
</tr>
<tr>
<td rowspan="2">
<p>CODED</p>
<p>NON-CODED</p>
</td>
</td>
<td rowspan="2">
<td>
<p>COD</p>
COD<p>NCOD</p>
<p>NCOD</p>
</td>
</td>
<td rowspan="2">NON-CODED</td>
<td>NON-CODED</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>
<tr>
FEW-VALUED<p>MANY-VALUED</p>
<td rowspan="2">
<p>FEW-VALUED</p>
<p>MANY-VALUED</p>
</td>
</td>
<td rowspan="2">
<td>
<p>FV</p>
FV<p>MV</p>
<p>MV</p>
</td>
</td>
<td rowspan="2">MANY-VALUED</td>
<td>MANY-VALUED</td>
</tr>
</tr>
<tr>
</table>
</table>


 
====Field constraints====
==== Field constraints ====
<p>
<p>More than one constraint may be set on a field. Foe example, if you only want to accept integer values between 5 and 99, then you can code:</p>
More than one constraint may be set on a field. For example, if you only want to accept integer values between 5 and 99, then you can code:</p>
 
<p class="code">DEFINE FIELD ''fieldname'' WITH INTGE 5 INTLE 99  
<p class="code">DEFINE FIELD <i>fieldname</i> WITH INTGE 5 INTLE 99
</p>
</p>
 
<table>
<table>
<caption>Field constraint attributes with the DEFINE command</caption>
<caption>Field constraint attributes with DEFINE command</caption>
<tr class="head">
<tr class="head">
<th>Attribute</th>
<th>Attribute</th>
Line 325: Line 309:
<th>Notes</th>
<th>Notes</th>
</tr>
</tr>
<tr>
<tr>
<td rowspan="2">
<td>
<p>UNIQUE</p>
UNIQUE<p>NON-UNIQUE</p>
<p>NON-UNIQUE</p>
</td>
</td>
<td rowspan="2">
<td>
<p>UNIQ</p>
UNIQ<p>NUNIQ</p>
<p>NUNIQ</p>
</td>
</td>
<td rowspan="2">NON-UNIQUE</td>
<td>NON-UNIQUE is default</td>
</tr>
<tr>
</tr>
</tr>
<tr>
<tr>
<td>
<td>
<p>LEVEL </p>
LEVEL
</td>
</td>
<td>
<td>
<p>LEV</p>
LEV
</td>
</td>
<td>
<td>
<p>See [[Security]]</p>
See [[Model 204 security features]]
</td>
</td>
</tr>
</tr>
<tr>
</tr>
<tr>
<tr>
<td colspan="3">
<td colspan="3">
<p><center>Field length constraints</center></p>
<p><center><b>Field length constraints</b></center></p>
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>LENGTH-EQ</td><td>LEQ</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>LENGTH-EQ</td><td>LEQ</td><td></td>
<td>LENGTH-GE</td><td>LGE</td><td>Available as of V7.5</td>
</tr>
<tr>
<td>LENGTH-GE</td><td>LGE</td><td></td>
</tr>
<tr>
<td>LENGTH-LE</td><td>LLE</td><td></td>
</tr>
</tr>
<tr>
<tr>
<td>LENGTH-LE</td><td>LLE</td><td>Available as of V7.5</td>
</tr>
</tr>
 
<tr>
<tr>
<td colspan="3">
<td colspan="3">
<p><center>Integer value constraints</center><br>
<center><b>Integer value constraints</b></center>
(validate contents against permissible integer value)</p>
(validate contents against permissible integer value)
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>INTEGER-GE</td><td>INTGE</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>INTEGER-GE</td><td>INTGE</td><td></td>
<td>INTEGER-GT</td><td>INTGT</td><td>Available as of V7.5</td>
</tr>
<tr>
<td>INTEGER-GT</td><td>INTGT</td><td></td>
</tr>
<tr>
<td>INTEGER-LE</td><td>INTLE</td><td></td>
</tr>
</tr>
<tr>
<tr>
<td>INTEGER-LT</td><td>INTLT</td><td></td>
<td>INTEGER-LE</td><td>INTLE</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>INTEGER-LT</td><td>INTLT</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td colspan="3">
<td colspan="3">
<p><center>Float value constraints</center><br>
<center><b>Float value constraints</b></center>
(validate contents against permissible float value)</p>
(validate contents against permissible float value)
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>FLOAT-GE</td><td>FLTGE</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>FLOAT-GE</td><td>FLTGE</td><td></td>
<td>FLOAT-GT</td><td>FLTGT</td><td>Available as of V7.5</td>
</tr>
<tr>
<td>FLOAT-GT</td><td>FLTGT</td><td></td>
</tr>
</tr>
<tr>
<tr>
<td>FLOAT-LE</td><td>FLTLE</td><td></td>
<td>FLOAT-LE</td><td>FLTLE</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>FLOAT-LT</td><td>FLTLT</td><td></td>
<td>FLOAT-LT</td><td>FLTLT</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
</tr>
</tr>
<tr>
<tr>
<td colspan="3">
<td colspan="3">
<p><center>Date Time value constraints</center><br>
<center><b>Date Time value constraints</b></center>
(validate contents against permissible date times value)</p>
(validate contents against permissible date times value)
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>DATETIME-GE</td><td>DTGE</td><td></td>
<td>DATETIME-GE</td><td>DTGE</td><td>Available as of V7.5</td>
</tr>
<tr>
<td>DATETIME-GT</td><td>DTGT</td><td></td>
</tr>
</tr>
<tr>
<tr>
<td>DATETIME-LE</td><td>DTLE</td><td></td>
<td>DATETIME-GT</td><td>DTGT</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
<td>DATETIME-LT</td><td>DTLT</td><td></td>
<td>DATETIME-LE</td><td>DTLE</td><td>Available as of V7.5</td>
</tr>
</tr>
<tr>
<tr>
</tr>
<td>DATETIME-LT</td><td>DTLT</td><td>Available as of V7.5</td>
<tr>
</tr>
 
<tr>
</tr>
</tr>
</table>
</table>
 
==== Concatenated fields ====
==== Concatenated fields ====
<table>
<table>
<caption>Concatenated field attributes with the DEFINE command</caption>
<caption>Concatenated field attributes with the DEFINE command</caption>
Line 450: Line 431:
<th>Notes</th>
<th>Notes</th>
</tr>
</tr>
<tr>
</tr>
<tr>
<tr>
<td>CONCATENATION-OF</td>
<td>CONCATENATION-OF</td>
<td>CAT</td>
<td>CAT</td>
<td>all source fields must be EXACTLY-ONE</td>
<td>All source fields must be EXACTLY-ONE</td>
</tr>
<tr>
</tr>
</tr>
</table>
</table>
 
 
==== Automatic fields ====
==== Automatic fields ====
<table>
<table>
<caption>Automatic field attributes with the DEFINE command</caption>
<caption>Automatic field attributes with the DEFINE command</caption>
Line 471: Line 448:
<th>Notes</th>
<th>Notes</th>
</tr>
</tr>
<tr>
<tr>
<td>
<td>
<p>COUNT-OCCURRENCES-OF</p>
COUNT-OCCURRENCES-OF
</td>
</td>
<td>
<td>
<p>CTO</p>
CTO
</td>
</td>
<td>
<td>
<p>followed by what it is you're counting</p>
Followed by what it is you are counting;
<br>
not allowed for fields defined as REPEATABLE
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td colspan="3">
<td colspan="3">
<p><center>Tracking updates with automatic fields</center></p>
<center><b>Tracking updates with automatic fields</b></center>
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>CREATE-TIME</td><td>CRTM</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
</tr>
<tr>
<tr>
<td>CREATE-TIME</td><td>CRTM</td><td></td>
<td>CREATE-TIMEUTC</td><td>CRTMU</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
</tr>
<tr>
<tr>
<td>CREATE-TIMEUTC</td><td>CRTMU</td><td></td>
<td>UPDATE-TIME</td><td>UPTM</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
</tr>
<tr>
<tr>
<td>UPDATE-TIME</td><td>UPTM</td><td></td>
<td>UPDATE-TIMEUTC</td><td>UPTMU</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
</tr>
<tr>
<tr>
<td>UPDATE-TIMEUTC</td><td>UPTMU</td><td></td>
<td>CREATE-USER</td><td>CRUS</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
<tr>
<td>CREATE-USER</td><td>CRUS</td><td></td>
</tr>
<tr>
<td>UPDATE-USER</td><td>UPUS</td><td></td>
</tr>
</tr>
<tr>
<tr>
<td>UPDATE-USER</td><td>UPUS</td><td>Not allowed for fields defined as REPEATABLE</td>
</tr>
</tr>
</table>
</table>
 
 
==== Defining a field inside a field group ====
==== Defining a field inside a Repeating Field Group ====
 
 
<table>
<table>
<caption>Linking a field to a Repeating Field Group with the DEFINE command</caption>
<caption>Linking a field to a field group with the DEFINE command</caption>
<tr class="head">
<tr class="head">
<th>Attribute</th>
<th>Attribute</th>
Line 522: Line 502:
<th>Notes</th>
<th>Notes</th>
</tr>
</tr>
<tr>
<tr>
<td>FIELDGROUP</td>
<td>FIELDGROUP</td>
<td>FG</td>
<td>FG</td>
<td>If not the last attribute specified, requires an ' AND ' after it</td>
<td>If not the last attribute specified, requires ' AND ' after it</td>
</tr>
<tr>
</tr>
</tr>
</table>
</table>
 
 
 
===OCCURS and LENGTH clauses===
===OCCURS and LENGTH clauses===
<p>The variables n and m specified for OCCURS and LENGTH must be decimal numbers between 1 and 255. The PAD character can be specified in decimal, hexadecimal (X'xx'), or character (C'c') form, and can take on any value equivalent to a number between 0 and 255.</p>
<p>
<p>All preallocated fields (fields that have an OCCURS clause) must be defined before any records are added to the file. </p>
The variables n and m specified for OCCURS and LENGTH must be decimal numbers between 1 and 255. The PAD character can be specified in decimal, hexadecimal (X'xx'), or character (C'c') form, and can take on any value equivalent to a number between 0 and 255.</p>
<p>
All preallocated fields (fields that have an OCCURS clause) must be defined before any records are added to the file. </p>
<p class="note"><b>Note:</b> After records are loaded, you can add a preallocated field definition only by reinitializing the file, defining all the fields-including the new preallocated field-and reloading the records. Non-preallocated field definitions can be added at any time. </p>
<p class="note"><b>Note:</b> After records are loaded, you can add a preallocated field definition only by reinitializing the file, defining all the fields-including the new preallocated field-and reloading the records. Non-preallocated field definitions can be added at any time. </p>
===Defining field retrieval attributes===
===Defining field retrieval attributes===
<p>If you do not know if a field will be used in retrievals, you can define it initially as NON-KEY, NON-ORDERED, and NON-RANGE. Then, you will be able to monitor the use of the field in FIND statements using information written to the journal data set and redefine it as KEY, NUMERIC RANGE, or ORDERED when necessary.</p>
<p>
<p>For details, see [[ File Statistics and Tuning#Monitoring field retrievals in FIND statements|Monitoring field retrievals in FIND statements]].</p>
If you do not know if a field will be used in retrievals, you can define it initially as NON-KEY, NON-ORDERED, and NON-RANGE. Then, you will be able to monitor the use of the field in FIND statements using information written to the journal data set and redefine it as KEY, NUMERIC RANGE, or ORDERED when necessary.</p>
 
<p>
For details, see [[File statistics and tuning#Monitoring field retrievals in FIND statements|Monitoring field retrievals in FIND statements]].</p>
==Implementing the date-time stamp feature (DTS)==
==Implementing the date-time stamp feature (DTS)==
<p>The date-time stamp feature in <var class="product">Model&nbsp;204</var> lets you can easily discern when a record in a file was last changed. The date-time stamp feature is supported for ONLINE and BATCH204.</p>
<p>
 
The date-time stamp feature in <var class="product">Model&nbsp;204</var> lets you can easily discern when a record in a file was last changed. The date-time stamp feature is supported for ONLINE and BATCH204.</p>
<p>See [[Setting Up the Date-Time Stamp Field]] for the steps the System Manger must take before this feature is used, <br>
and [[Adding a Date-Time Stamp field]] for rules on using the feature.</p>
<p>
See [[Setting up the date-time stamp field]] for the steps the System Manger must take before this feature is used.
</p>
<p>
See [[Adding a date-time stamp field]] for rules about using the date-time stamp feature.</p>


==Preventing definition of new field names==
==Preventing definition of new field names==
<p><var class="product">Model&nbsp;204</var> permits a user to define new fields at any time. This is an advantage in some applications, because it enables the file to evolve beyond its original definition. If your site does not want users to add new field names, reset the FOPT parameter to X'01' from its default value of X'00'. This file option causes <var class="product">Model&nbsp;204</var> to issue the following response, when a user issues a DEFINE command:</p>
<p>
<var class="product">Model&nbsp;204</var> permits a user to define new fields at any time. This is an advantage in some applications, because it enables the file to evolve beyond its original definition. If your site does not want users to add new field names, reset the <var>[[FOPT parameter|FOPT]]</var> parameter to X'01' from its default value of X'00'. This file option causes <var class="product">Model&nbsp;204</var> to issue the following response, when a user issues a DEFINE command:</p>
<p class="code"><b></b>*** M204.1261: NEW FIELD NAMES NOT PERMITTED
<p class="code"><b></b>*** M204.1261: NEW FIELD NAMES NOT PERMITTED
</p>
</p>
<p>Regardless of the setting of the [[FOPT parameter]], users with file manager privileges (see the [[PRIVDEF parameter]]) can define new fields at any time. See the discussion in [[FOPT parameter]] for more detail. </p>
<p>
<p>&nbsp;</p>
Regardless of the setting of the <var>FOPT</var> parameter, users with file manager privileges (see the <var>[[PRIVDEF parameter|PRIVDEF]]</var> parameter) can define new fields at any time. See the [[FOPT parameter]] discussion for more detail. </p>
 
[[Category:File management]]
[[Category:Model 204 files]]

Latest revision as of 21:21, 7 April 2017

This chapter describes the use of the DEFINE FIELD command, which allows you to define the fields in a file. For the full syntax, follow that link.

Defining fields

After you CREATE and INITIALIZE a Model 204 file, use the DEFINE command or the IFDFLD Host Language Interface function to establish the names and types of the fields in the file.

Syntax

The format of the DEFINE command is:

DEFINE FIELD name [(attribute [,[attribute ...]]) | WITH [attribute][,[attribute ...]]]

where:

  • name is a 1 to 255 character name that must begin with a letter and can contain any alphanumeric characters, including spaces, except:

    ?? ?$ ?& @ (or an alternative delete character) # (or an alternative flush character) ;

  • attribute is a member of the list in Field attributes.

    If you specify the ORDERED attribute, you can follow it with a list of qualifying parameters that designate the type of ordering and the space utilization characteristics of the Ordered Index. See the discussion of the ORDERED attribute in ORDERED and NON-ORDERED attributes.

Example

In the following example, the field CUSTID is named and given the ORDERED CHARACTER attribute:

DEFINE FIELD CUSTID ORDERED CHARACTER

Specify as many field attributes as needed from Field attributes. For each attribute pair shown in the list, only one of the alternatives can be specified; conflicting attributes, such as KEY and NON-KEY, cannot be used together in a single description.

Note: Every attribute has a default value. Therefore, you only need to specify the attribute if it is not the default.

When to use the FIELD keyword

The keyword FIELD is required before field names that begin with the word FIELD, PRINTER, or DATASET. It is optional with other field names. If FIELD is specified, only one field can be defined or redefined per command. For example:

DEFINE FIELD POLICYHOLDER DEFINE POLICYHOLDER

Each example above defines a field with the name POLICYHOLDER. The following example defines a field with the name FIELD LOCATION:

DEFINE FIELD FIELD LOCATION

Defining sort key, hash key, and record security fields

The DEFINE command cannot be used to define sort key fields, hash key fields, or record security fields. These fields can be defined only with the INITIALIZE command and the appropriate parameter settings.

Field attributes

The attributes listed in the following tables are introduced in Field design, along with a summary of the rules follow in assigning them. A number of the attributes have additional optional attributes (in particular, see the ORDERED attribute) that can be specified with the DEFINE FIELD command, which are also described in Field design.

Indexing attributes

The overall effect of the defaults is that, unless specified, the field is not indexed.

Indexing field attributes with the DEFINE command
AttributeAbbreviationDefault
ORDERED CHARACTER

NON-ORDERED

ORD CHAR

NORD

NON-ORDERED
ORDERED NUMERIC

NON-ORDERED

ORD NUM

NORD

NON-ORDERED
KEY

NON-KEY

 

NKEY

NON-KEY
FRV

NON-FRV

The ORD attribute is preferable; shown for compatibility.

 

NFRV

NON-FRV
[NUMERIC] RANGE

NON-RANGE

Obsolete; supported for compatibility.

NR

NNR

NON-RANGE

Data types

In most cases, only one of these may be specified on any field (see the UTF attributes). The default is STRING

Data type attributes with the DEFINE command
Attribute Abbreviation Notes
STRING STR
BINARY BIN
BINARY-LARGE-OBJECT

CHARACTER-LARGE-OBJECT

BLOB

CLOB

Must have Table E enabled

FLOAT FLT Must have LEN specified
DATETIME DT
UTF-8

UTF-16

UTF8

UTF16

Must be used in conjunction with the BLOB or CLOB attribute

VISIBLE

INVISIBLE

VIS

INV

Data content attributes

Data content field attributes with the DEFINE command
Attribute Abbreviation Default

LENGTH m

LEN m

No preallocated length

OCCURS n OCC n No preallocated occurrences

PAD character

 

character = X'00'

DEFERRABLE

NON-DEFERRABLE

DEF

NDEF

DEFERRABLE
UPDATE IN PLACE

UPDATE AT END

UP

UE

UPDATE IN PLACE
DEFAULT-VALUE

STORE-DEFAULT

STORE-NULL

DV

SD

SN

 

LITERAL

LITERAL

AT-MOST-ONE

EXACTLY-ONE

REPEATABLE

ONE

EXONE

REPT

REPT (except in 1NF files), or inside a field group (where it is EXONE)

CODED

NON-CODED

COD

NCOD

NON-CODED
FEW-VALUED

MANY-VALUED

FV

MV

MANY-VALUED

Field constraints

More than one constraint may be set on a field. For example, if you only want to accept integer values between 5 and 99, then you can code:

DEFINE FIELD fieldname WITH INTGE 5 INTLE 99

Field constraint attributes with DEFINE command
Attribute Abbreviation Notes
UNIQUE

NON-UNIQUE

UNIQ

NUNIQ

NON-UNIQUE is default

LEVEL

LEV

See Model 204 security features

Field length constraints

LENGTH-EQLEQAvailable as of V7.5
LENGTH-GELGEAvailable as of V7.5
LENGTH-LELLEAvailable as of V7.5
Integer value constraints

(validate contents against permissible integer value)

INTEGER-GEINTGEAvailable as of V7.5
INTEGER-GTINTGTAvailable as of V7.5
INTEGER-LEINTLEAvailable as of V7.5
INTEGER-LTINTLTAvailable as of V7.5
Float value constraints

(validate contents against permissible float value)

FLOAT-GEFLTGEAvailable as of V7.5
FLOAT-GTFLTGTAvailable as of V7.5
FLOAT-LEFLTLEAvailable as of V7.5
FLOAT-LTFLTLTAvailable as of V7.5
Date Time value constraints

(validate contents against permissible date times value)

DATETIME-GEDTGEAvailable as of V7.5
DATETIME-GTDTGTAvailable as of V7.5
DATETIME-LEDTLEAvailable as of V7.5
DATETIME-LTDTLTAvailable as of V7.5

Concatenated fields

Concatenated field attributes with the DEFINE command
Attribute Abbreviation Notes
CONCATENATION-OF CAT All source fields must be EXACTLY-ONE


Automatic fields

Automatic field attributes with the DEFINE command
Attribute Abbreviation Notes

COUNT-OCCURRENCES-OF

CTO

Followed by what it is you are counting;
not allowed for fields defined as REPEATABLE

Tracking updates with automatic fields
CREATE-TIMECRTMNot allowed for fields defined as REPEATABLE
CREATE-TIMEUTCCRTMUNot allowed for fields defined as REPEATABLE
UPDATE-TIMEUPTMNot allowed for fields defined as REPEATABLE
UPDATE-TIMEUTCUPTMUNot allowed for fields defined as REPEATABLE
CREATE-USERCRUSNot allowed for fields defined as REPEATABLE
UPDATE-USERUPUSNot allowed for fields defined as REPEATABLE

Defining a field inside a field group

Linking a field to a field group with the DEFINE command
Attribute Abbreviation Notes
FIELDGROUP FG If not the last attribute specified, requires ' AND ' after it

OCCURS and LENGTH clauses

The variables n and m specified for OCCURS and LENGTH must be decimal numbers between 1 and 255. The PAD character can be specified in decimal, hexadecimal (X'xx'), or character (C'c') form, and can take on any value equivalent to a number between 0 and 255.

All preallocated fields (fields that have an OCCURS clause) must be defined before any records are added to the file.

Note: After records are loaded, you can add a preallocated field definition only by reinitializing the file, defining all the fields-including the new preallocated field-and reloading the records. Non-preallocated field definitions can be added at any time.

Defining field retrieval attributes

If you do not know if a field will be used in retrievals, you can define it initially as NON-KEY, NON-ORDERED, and NON-RANGE. Then, you will be able to monitor the use of the field in FIND statements using information written to the journal data set and redefine it as KEY, NUMERIC RANGE, or ORDERED when necessary.

For details, see Monitoring field retrievals in FIND statements.

Implementing the date-time stamp feature (DTS)

The date-time stamp feature in Model 204 lets you can easily discern when a record in a file was last changed. The date-time stamp feature is supported for ONLINE and BATCH204.

See Setting up the date-time stamp field for the steps the System Manger must take before this feature is used.

See Adding a date-time stamp field for rules about using the date-time stamp feature.

Preventing definition of new field names

Model 204 permits a user to define new fields at any time. This is an advantage in some applications, because it enables the file to evolve beyond its original definition. If your site does not want users to add new field names, reset the FOPT parameter to X'01' from its default value of X'00'. This file option causes Model 204 to issue the following response, when a user issues a DEFINE command:

*** M204.1261: NEW FIELD NAMES NOT PERMITTED

Regardless of the setting of the FOPT parameter, users with file manager privileges (see the PRIVDEF parameter) can define new fields at any time. See the FOPT parameter discussion for more detail.