The data that you retrieve goes into the record variable you specify in the statement, and the exact behavior of the statement depends on the way you have stereotyped your record variable.
The only forms of the get statement that you can use when you specify a record with the CSVRecord stereotype are get next for single variables and get for arrays.
EGL then reads the next row from the file, breaking it down into separate strings based on the value of the delimiter property. If there are more strings than fields in the record, EGL ignores the extra strings.
Finally, EGL uses the strings to update the fields in the record. EGL uses the existing conversion rules to convert the strings to the appropriate values. EGL expects "true" and "false" as values for a BOOLEAN field; case is ignored. If no string corresponds to a particular field, that field receives a null value.
The I/O error status of the array is set to noRecordFound if the file is empty (no rows were read, the size of the array is zero). The I/O error status is set to endOfFile if the entire file was read into the array.
EGL closes the file after it finishes reading.
When you issue a get statement that references a record with the IndexedRecord stereotype, the key value in the record determines the record to be retrieved from the file.
The get statement (with the forUpdate option) prevents other programs from changing the record; for more information, see "Compatibility" in this topic.
1, 2, 2, 2, 3, 4
Each of the following tables illustrates the effect of running a sequence of EGL statements on the same indexed record.
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value |
---|---|---|---|
get | 2 | 2 (the first of three) | duplicate |
get next | any | 3 | -- |
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value |
---|---|---|---|
set position | 2 | no retrieval | -- |
get next | any | 2 (the first of three) | duplicate |
get next | any | 2 (the second) | duplicate |
get next | any | 2 (the third) | -- |
get next | any | 3 | -- |
1, 2, 2, 2, 3, 4
Each of the following tables illustrates the effect of running a sequence of EGL statements on the same indexed record.
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value |
---|---|---|---|
get | 3 | 3 | -- |
get previous | any | 2 (the first of three) | duplicate |
get previous | any | 2 (the second) | duplicate |
get previous | any | 2 (the third) | -- |
get previous | any | 1 | -- |
get previous | any | -- | endOfFile |
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value |
---|---|---|---|
set position | 2 | -- | -- |
get next | any | 2 (the first) | duplicate |
get next | any | 2 (the second) | duplicate |
get previous | any | 1 | -- |
get previous | any | -- | endOfFile |
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value |
---|---|---|---|
set position | 1 | -- | -- |
get previous | any | 1 | -- |
get previous | any | -- | endOfFile |
The get statement is not available for serial records.
myCustomer CustomerRecord; // create record variable myCustomer.customerNumber = 1001; // set key in record variable try get myCustomer; onException(fileErr FileIOException) myErrorHandler(fileErr); // exits the program end