Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A <write-statement> writes data to the file underlying <marked-file-number>.
-
write-statement = "Write" marked-file-number "," [output-list]
Static Semantics.
§ The semantics of <marked-file-number> in this context are those of a <file-number> element that consisted of that same <marked-file-number> element.
§ If a <write-statement> contains no <output-list>, the effect is as if <write-statement> contains an <output-list> with an <output-clause> of "" (a zero-length string), followed by a <char-position> of ",".
Runtime Semantics.
An error (number 52, "Bad file name or number") is raised if the file number value (section 5.4.5.1.1) of <file-number> is not a currently-open (section 5.4.5.1) file number (section 5.4.5).
If <output-list> is not present, the implementation-defined line termination sequence is written to the file associated with file number value starting at its current file-pointer-position. The current file-pointer-position is set immediately after the line termination sequence.
Otherwise, for each <output-item> in <output-list> proceeding in left to right order:
If <output-clause> consists of an <output-expression>:
The <output-expression> is evaluated to produce an output string value and characters of the string are written to the file associated with file number value starting at its current file-pointer-position.
Write a comma character to the file unless this is the final <output-clause> and its <char-position> is neither a "," or an explicitly occurring ";".
Advance the current file-pointer-position to immediately follow the last output character.
If while performing any of these steps the number of characters in the current line (section 5.4.5) reaches the maximum line length (section 5.4.5) the line termination sequence is immediately written and output continues on the next line.
If <output-clause> consists of a <spc-clause>:
If space count (section 5.4.5.8.1) is less than or equal to maximum line length of the file number value or if the file number value does not have a maximum line length, let s be the value of space count.
Otherwise, space count is greater than the maximum line length. Let s be the value (space count modulo maximum line length).
If the is a maximum line width and s is greater than maximum line width minus current line position let s equal s minus (maximum line width minus current line position). The line termination sequence is immediately written and current file-pointer-position is set to beginning of the new line.
Write s space characters to the file associated with file number value starting at its current file-pointer-position and set the current file-pointer-position to the position following that last such space character.
If the <char-position> element is a "," write a comma character to the file and advance the current file-pointer-position.
If while performing any of these steps the number of characters in the current line (section 5.4.5) reaches the maximum line length (section 5.4.5) the line termination sequence is immediately written and output continues on the next line.
If <output-clause> consists of a <tab-clause> that includes a <tab-number-clause> then do the following steps:
If tab number (section 5.4.5.8.1) is less than or equal to maximum line length of the file number value or if the file number value does not have a maximum line length, let t be the value of tab number.
Otherwise, tab number is greater than the maximum line length. Let t be the value (tab number modulo maximum line length).
If t less than or equal to the current line position, output the line termination sequence. Set the current file-pointer-position is set to beginning of the new line.
Write t minus current line position space characters to the file associated with file number value starting at its current file-pointer-position and set the current file-pointer-position to the position following that last such space character.
If the <char-position> element is a "," write a comma character to the file and advance the current file-pointer-position.
If while performing any of these steps the number of characters in the current line (section 5.4.5) reaches the maximum line length (section 5.4.5) the line termination sequence is immediately written and output continues on the next line.
Otherwise, <output-clause> consists of a <tab-clause> that does not includes a <tab-number-clause> so do the following steps:
Write a comma character and advance the current file-pointer-position.
If the <char-position> element is a "," write a comma character to the file and advance the current file-pointer-position.
If while performing any of these steps the number of characters in the current line (section 5.4.5) reaches the maximum line length (section 5.4.5) the line termination sequence is immediately written and output continues on the next line.
If the <char-position> of the last <output-item> is neither a "," nor an explicitly occurring ";" the implementation-defined line termination sequence is output and the current file-position-pointer is set to the beginning of the new line.
The output string value of an <output-expression> is determined as follows:
If the evaluated data value of the <output-expression> is the Boolean data value True, the output string is ""#TRUE#".
If the evaluated data value of the <output-expression> is the Boolean data value False, the output string is "#FALSE#".
If the evaluated data value of the <output-expression> is the data value Null, the output string is "#NULL#".
If the evaluated data value of the <output-expression> is an Error data value the output string is "#ERROR " followed by the error code Let-coerced to String followed by the single character "#".
If the evaluated data value of the <output-expression> is a String data value the output string is the data value of the String data element with surrounding double quote (U+0022) characters.
If the evaluated data value of the <output-expression> is any numeric data value other than a Date the output string is the evaluated data value of the <output-expression> Let-coerced to String ignoring any implementation dependent locale setting and using "." as the decimal separator.
If the evaluated data value of the <output-expression> is a Date data value the output string is a String data value of the form #yyyy-mm-dd hh:mm:ss#. Hours are specified in 24-hour form. If both the date is 1899-12-30 and the time is 00:00:00 only the date portion is output. Otherwise if the date is 1899-12-30 only the time portion is output and if the time is 00:00:00 only the date portion is output.
Otherwise, the output string is the evaluated data value of the <output-expression> Let-coerced to String with the data value of the string surrounded with double quote (U+0022) characters.