Writes a record to a file from data stored in variables, columns, or literals.
WRITE {filenum_lit|_var|_col} FROM {{{txt_lit|_var|_col}|{date_var|_col}|num_col} [:len_int_lit|_var|_col]}|{num_lit|_var:len_int_lit|_var|_col}}... [STATUS=status_num_var]
Number assigned in OPEN to the file to write.
{{txt_lit|_var|_col}|{date_var|_col}|num_col} [:len_int_lit|_var|_col]}|{num_lit|_var:len_int_lit|_var|_col}
Specifies one or more variables to write. len_int_lit|_var|_col specifies the length of each field of data.
An optional variable into which a write status is returned.
The file must already be opened for writing.
If length is specified, the variable is either truncated at that length or padded with spaces to that length. If length is not specified (for string variables or database columns), the current length of the variable is used.
When writing numeric variables, the length argument is required. Only 1, 2, or 4 byte binary integers are written. Floating point values are not supported directly in WRITE. However, you can first convert floating point numbers to strings and then write the string.
When writing binary data the file must be open using the FIXED or FIXED‑NOLF qualifiers. The file is not portable across platforms since binary numbers are represented differently.
When writing a date variable or column, the date is converted to a string according to the following rules:
For DATETIME columns and Production Reporting DATE variables, Production Reporting uses the format specified by SQR_DB_DATE_FORMAT. If not set, Production Reporting uses the first database-dependent format in Table 61, Default Formats by Database.
For DATE columns, Production Reporting uses the format specified by SQR_DB_DATE_ONLY_FORMAT. If not set, Production Reporting uses the format in Table 62, DATE Column Formats.
For TIME columns, Production Reporting uses the format specified by SQR_DB_TIME_ONLY_FORMAT. If not set, Production Reporting uses the format in Table 63, TIME Column Formats.
Text literals take the length of the literal.
Files opened for writing are treated as having variable-length records. If you need a fixed-length record, specify a length for each variable written to the file.
The total length of the variables and literals being written must not be greater (but can be less) than the record length specified when the file was opened. Records are not padded, but are written with the total length of all variables in WRITE.
If STATUS is specified, Production Reporting returns 0 if the write is successful; otherwise, it returns the value of errno, which is system-dependent.
write 5 from $name:20 $city:15 $state:2 write 17 from $company ' - ' $city ' - ' $state ' ' $zip write #j2 from #rate:2 #amount:4 #quantity:1 move #total to $tot 99999.99 ! Convert floating point to ! string. write 1 from $tot let $date1 = datenow() ! Put the current date and time ! into DATE variable write 3 from $date1:20