WRITE (IFILE)
ANSI
The WRITE instruction transfers information from program variables into a disk file.
|
|
|
|
|
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
file
Required. A previously defined and opened IFILE variable in which data is written.
key
Optional. A previously defined Character String Variable, String Expression or Numeric Variable containing the index key associated with this record.
list
Optional. Any combination of previously defined Character String Variables, Numeric Variables, String Expressions, string or numeric ARRAYs, individual array elements, VARLISTs of string or numeric variables, or valid Disk I/O List Controls.
;
Optional. A semicolon indicating Partial I/O.
columnname
Required. The column name as specified in the VIEW that was assigned to the file variable by the OPEN or PREPARE instruction. The column named is not case sensitive.
variable
Required. The variable that has been previously declared and loaded with data to be written.
Flags Affected: LESS, OVER, ZERO
Note the following:
The Logical String of {key} is the index key associated with this record. A String Expression may be used for {key}; its evaluated string result supplies the index key.
A Numeric Expression is not supported for {key}. A Logical/Conditional comparison expression is also not supported for {key}. Numeric Variables remain valid key operands.
If {key} is not specified, the key is constructed using the data in {list}.
Duplicate ISAM keys are allowed unless the `N' option was used during the most recent indexing of the file. The `N' option in the INDEX utility signifies that duplicate ISAM keys are not allowed and that a trappable I/O error occurs if an attempt is made to write or insert a duplicate key to the file.
{list} may be any combination of character string and/or numeric variables (including arrayed items), character string and/or numeric literals, Ctrl values and/or supported list controls separated by commas. If an ARRAY variable is given without a specific array element designated, all elements of the array are processed.
A {list} may include String Expressions. A String Expression used as a {list} item must produce a string value.
A parenthesized Numeric Expression such as ( $1 ) or ( $1 + $2 ) is not supported as a {list} item. A comparison expression that produces a logical numeric result is also not valid as a String Expression list item.
Ctrl values and literals are written to the disk exactly as specified in {list}.
The supported list controls are as follows:
|
Control |
Function |
|
Enable space compression | |
|
Disable space compression | |
|
Disable *CDFON | |
|
Enable comma-delimited Field support | |
|
Disable *EDION | |
|
Enable Electronic Data Information support | |
|
Data is written in the case in which it was stored | |
|
Forces output of only the Logical String | |
|
Minus overpunch negative numeric variables | |
|
Disable *LL (default) | |
|
lower case characters are converted to upper case before being written | |
|
Zero-fill numeric variables | |
|
Blank-fill zero numeric variables |
Tabbing is not allowed with the WRITE instruction. If tabbing is desired, the WRITAB instruction should be used.
If a semi-colon (;) terminates the list, the rules applying to partial writes apply (see Partial I/O). Partial IO is not allowed for SQLIO.
Any records written to a fixed length record file that are shorter than the declared record size are padded with blanks and the LESS flag is set.
Any records written to a fixed length record file that are longer than the declared record size or to a variable length record file that are longer than the maximum record size are truncated and the OVER flag is set.
When using the single unlocking mode, a WRITE to a record that is not locked unlocks the currently locked record before the WRITE begins.
When using the single unlocking mode, a WRITE to a locked record unlocks the record when the operation completes.
When a view schema is assigned to an IFILE variable (9.4), the WRITE instruction can optionally use the column name syntax (format 2 above). When the column name syntax is being used, all variables used in the instruction variable list must have column names specified. When the column name syntax is not being used, no variables in the instruction variable list can have column names.
If the column name syntax specified with the 'columnname' parameter is being used, the 'columnname' parameter can be one of the following:
Column name as specified by the VIEW column definitions.
@{svar} where {svar} is a variable that contains the column name as specified by the VIEW column definitions.
Example:
If the column name syntax format is being used, partial IO using the semicolon character (;) is not allowed and a runtime error will result.
If the column name syntax format is being used and all of the view column names are not included in the WRITE variable list, any unspecified fields are either blank filled or filled with a default value specified in the view schema. For a file opened or created with fixed length records, the WRITE instruction writes the full record with appropriate default data for unspecified fields. For a file opened or created with variable length records, the WRITE instruction writes all of the fields up to and including the last column that has been specified with unspecified fields being appropriately filled with default data.
Example 1:
|
|
|
|
|
Logical file: |
DATAFILE |
|
Method: |
Index (KEY1 is a previously defined character string variable) |
|
Variables: |
VAR1, VAR2 and BALANCE |
|
List controls: |
*ZF zero-fills the numeric variable BALANCE |
|
Partial write: |
No semi-colon specified (writes End Of Record (EOR) mark) |
Example 2:
|
|
|
|
|
Logical file: |
MYFILE |
|
Method: |
Index (KEY2 is a previously defined character string variable) |
|
Variables: |
FIELD1 and FIELD2 |
|
List controls: |
*LL enabled for FIELD1 only (*PL disables it after FIELD1) |
|
Partial write: |
Semi-colon specifies partial WRITE (no EOR) |
Example 3:
|
|
|
|
|
Logical file: |
MYFILE |
|
Method: |
Index (the key is constructed using the contents of FIELD1 and FIELD2) |
|
Variables: |
FIELD1 and FIELD2 |
|
List controls: |
none |
|
Partial write: |
none |
See Also: READ (IFILE), DELETE (IFILE), UPDATE (IFILE), Disk I/O Instructions
![]() |