6 - 3 6 - 3
MELSEC-Q
6 I/O Processing of Data Files
6.2 Sequential File I/O Procedures
The following shows an overview of I/O procedures for sequential files.
In sequential files, either read operation or
write operation can be performed per opening
of the file.
(1) Writing data to a file
1) Open a file in output mode.
PRINT #n, <write data>,
PRINT #n, USING " ", <write data>,
OPEN "<filename>" FOR OUTPUT AS #n
2) Write the data in the file
3) Close the file
CLOSE #n
• n indicates the file number.
• For details on assigning <filename>,
see Appendix 1.
Do not forget to use the CLOSE instruction when
data write is complete.
If the CLOSE instruction is not used, the data may
not be written.
………
………
………
When appending (writing) data to a sequential file that already contains data, and if
"OPEN "<filename>" FOR APPEND AS #n" is used to open the file, a new data is
written following the existing data. If "OPEN "<filename>" FOR OUTPUT AS #n" is
used to open the file, all existing data is deleted and the data will be written from the
beginning.
(2) Reading data from a file
1) Open the file in Input mode.
INPUT #n, <variable to store the data read>,
LINE INPUT #n, <variable to store the data read>,
OPEN " <filename> " FOR INPUT AS #n
2) Read the data from the file.
3) Close the file.
CLOSE # n
………
………