MATREADCSV |
![]() ![]() ![]() |
The MATREADCSV statement reads a CSV format line of text from a directory file record previously opened for sequential access and parses it into the elements of a dimensioned matrix.
Format
MATREADCSV matrix FROM file.var {THEN statement(s)} {ELSE statement(s)}
where
At least one of the THEN and ELSE clauses must be present.
A line of text is read from the file. It is then parsed according to the CSV format rules, placing the elements into successive elements of the matrix. If successful, the THEN clause is executed and the STATUS() function would return zero.
If there are fewer data items in the line of text than the number of variables supplied, the remaining elements of the matrix will be set to null strings. If the line of text has more data items than the number of elements in the matrix, the excess data is placed in the zero element as for MATPARSE.
If there are no further fields to be read, the ELSE clause is executed and the STATUS() function would return ER$RNF (record not found). The target matrix will be unchanged.
The CSV rules are described under the WRITECSV statement.
Example
DIM DETAILS(10) LOOP MATREADCSV DETAILS FROM DELIVERY.F ELSE EXIT GOSUB PROCESS.DELIVERY.DETAILS REPEAT
This program fragment reads CSV format lines of text from the record open for sequential access via the DELIVERY.F file variable into elements of the DETAILS matrix. It then calls the PROCESS.DELIVERY.DETAILS subroutine to process the new item. The loop terminates when the ELSE clause is executed when all fields have been processed.
See also: CLOSESEQ, NOBUF, OPENSEQ, READBLK, READSEQ, SEEK, WEOFSEQ, WRITEBLK, WRITECSV, WRITESEQ, WRITESEQF |