Partial I/O
Partial I/O allows processing of a portion of a record, followed by other intermediate processing, before the remainder of the record is processed. Partial I/O is possible through use of a semi- colon (;) as the terminator for an I/O instruction. The semi-colon at the end of an I/O list instructs the program to leave the file pointers positioned immediately after the last character processed, rather than skipping to the beginning of the next data record. Consider the following example:
A data file has two types of records (each in a different format) as follows:
|
Position: |
1234567890123456789012345678901234567890 |
|
Type 1 : |
1NAME ADDRESS CITY ST |
|
Type 2 : |
2 234.67 100.00 50.00 84.67 .00 |
By doing a partial read on the first position only and then following with another read, it is possible to determine which type of record is being read:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is possible to perform multiple partial reads on the same record before continuing. If the End Of Record (EOR) is reached during a partial read, all variables are processed as defined in the previous sections. To continue processing the next logical record, a non-partial read must be performed to complete the reading of the record and position the file pointer at the next record.
It is also possible to write part of a data record, do additional processing and then write the rest of the record. If the write list is terminated with a semi-colon (;), the program does not automatically write the End Of Record (EOR - see End Of Record section). Instead, it remains positioned so additional writes to the data record are possible. This could be done as follows:
|
Position: |
1234567890123456789012345678901234567890 |
|
Type 1 : |
1NAME ADDRESS CITY ST |
|
Type 2 : |
2 234.67 100.00 50.00 84.67 |
Using this format, the following example performs a partial write to the first position of the file, followed by additional processing that determines what the remainder of the record should contain. The rest of the record is then written without partial I/O.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
As with the read, it is also possible to perform multiple partial write operations before continuing with processing. Any EOR must be explicitly written or a non-partial write must be performed (as above). In the following example, the variable EOR has already been defined as the necessary End Of Record terminator:
|
|
|
|
The semi-colon at the end of the write is necessary to prevent the program from writing an additional End Of Record (EOR). It is not possible to perform partial output on IFILE and AFILE definitions.
Partial IO is not permitted when using SQLIO.
See Also: Disk I/O Instructions
![]() |