WRITE

Function

Writes a record to a file from data stored in variables, columns, or literals.

Syntax

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]

Arguments

filenum_lit|_var|_col

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.

STATUS

An optional variable into which a write status is returned.

Description

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:

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.

Examples

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				

See Also

OPEN, CLOSE, and READ