WRITECSV |
![]() ![]() ![]() |
The WRITECSV statement writes data at the current file position in a record previously opened using OPENSEQ. The data to be written is assembled from one or more variables and written in CSV format.
Format
WRITECSV var1, var2, ... TO file.var {ON ERROR statement(s)} {THEN statement(s)} {ELSE statement(s)}
where
At least one of the THEN and ELSE clauses must be present.
The data in the named variables is assembled as a CSV format text string which is then written to the file with a newline appended. The THEN clause is executed if the WRITECSV is successful.
The ELSE clause is executed if the WRITCSV fails. The STATUS() function will indicate the cause of the error.
The ON ERROR clause is executed for serious fault conditions such as errors in a file's internal control structures. The STATUS() function will return an error number. If no ON ERROR clause is present, an abort would occur.
CSV Format
CSV format is used by many applications. QM adheres to the CSV standard (RFC 4180).
Items are enclosed in double quotes if they contain commas or double quotes. Embedded double quotes are replaced by a pair of double quotes.
Examples
WRITECSV PROD.NO, QTY TO SEQ.F ELSE STOP 'Write error'
This program fragment writes the contents of the PROD.NO and QTY variables as a CSV item to a file previously opened to file variable SEQ.F.
WRITECSV S<1>, S<2>, S<3> TO SEQ.F ELSE STOP 'Write error'
This program fragment writes the contents of fields 1 to 3 of S as CSV data to a file previously opened to file variable SEQ.F.
WRITECSV S TO SEQ.F ELSE STOP 'Write error'
If dynamic array S in the previous example had only three fields, this program fragment writes exactly the same data, treating each field as a separate CSV item.
See also: CLOSESEQ, NOBUF, OPENSEQ, READBLK, READCSV, READSEQ, WEOFSEQ, WRITESEQ, WRITEBLK, WRITESEQF |