READFILE (RF)...ENDREAD
Syntax
READFILE (<File id>, <File layout(s)>[, <Start record number>][, SKIPCLEAR])
<Code lines>
ENDREAD
Description
Creates a loop that reads data records sequentially from a file.
Diagram
Returned value type
None
Parameters
| Parameter | Description |
|---|---|
| <File id> | Identifier by which the file is referenced. This identifier cannot be used for the READFILE and the file functions ADDREC, DELETEREC, LOCATE, UPDATEREC or READ at once. This means that if you also want to use these functions, you have to do this through another <File id>. Normally the READFILE command will lock the file during the transaction, but in the Application Options it is possible to overwrite this option by checking the 'Execute instruction ReadFile in shared mode' checkbox. |
| <File layouts> | One or more file layouts to use for organizing the file that is referred by <File id>. |
| <Start record number> | When set, the file is read from the record after this recordnumber. |
| SKIPCLEAR | With this option an eventual CLEARATFIRSTREAD option set in the NAMEFILE command will not be executed (i.e. the existing file will not be cleared when the READFILE is the first action on the file after the NAMEFILE command). |
Remarks
When the file has a record ending character sequence set and the line length is greater than the record length, the remaining data between the end of the defined record layout and the record ending character sequence will be ignored. For more flexibility, e.g. to compare data from multiple files, you will need another construction to write your instructions. Please note the safety precautions, before applying data files to your program.
|
When <Start record number> is used on a file with a dynamic record length, this will only work when already a number of records have been read from the file. This is needed for the system to detect that the file contains a dynamic record length. When using <Start record number> in the first read from the file, a fixed record length is assumed. This will lead to unpredictable results for files with a dynamic record length. |
Examples
// Reads file 'File1.txt' into record layout 'rec_layout1'
namefile (file1, 'File1.txt')
readfile (file1, rec_layout1)
rou1 ()
if file1.eof // Last record
rou2 ()
endif
endread
// Reads file 'Tile1.txt' into record layouts 'rec_layout1'
// and 'rec_layout2', starting at record 4
namefile (file1, 'File1.txt')
readfile (file1, rec_layout1, rec_layout2, 3)
rou3 ()
if file1.eof // Last record
rou4 ()
endif
endread