WRITE (FILE)
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 FILE variable in which data is written.
record
Required. A previously defined Numeric Variable that selects the record written.
list
Optional. Any combination of previously defined Character String Variables, Numeric Variables, 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: NONE
Note the following:
If {record} is equal to or greater than zero, it designates a sector in the file for random or direct access (see Random Access Method). The first sector in the file is zero(0) and each subsequent sector increments the reference appropriately. The relative sector size defaults to 256 bytes butmay be adjusted using the BUFFER/FIX/FIXED FILE declaration parameter.
If {record} is a negative number equal to -1, -2, -3 or -4, it indicates sequential file processing (see Sequential Access Method). The differences are as follows:
|
Control |
Function |
|
-1 |
Sequential forward processing |
|
-2 |
Sequential forward processing |
|
-3 |
Position to End Of File (EOF) prior to processing |
|
-4 |
Sequential backward processing |
{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.
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 relevant to partial writes apply (see Partial I/O). Partial IO is not allowed for SQLIO.
Space compression is disabled unless explicitly enabled through *+.
Any short records written to the file are padded with blanks to the record length.
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 FILE 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.
See Also: Example Code, READ (FILE), WRITAB, WEOF, Disk I/O Instructions
![]() |