The EGL get previous statement either reads the previous row from a relational-database result set or reads the previous record in the file that is associated with a specified EGL indexed record.
You can use this statement for a relational-database result set only if you specified the scroll option in the related open statement. The scroll option is available only if you are generating output in Java™.
An example for an indexed record is as follows:
record1.hexKey = "FF"; set record1 position; try get previous record1; onException myErrorHandler(8); return; end while (record1 not endOfFile) processRecord(record1); // handle the data try get previous record1; onException myErrorHandler(8); return; end end
Details on the get previous statement depend on whether you are using an indexed record or are concerned with SQL processing.
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.
The next three tables apply to EGL-generated COBOL code.
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value for COBOL |
---|---|---|---|
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 | — |
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value for COBOL |
---|---|---|---|
set (of the form set record position) | 2 | — | — |
get next | any | 2 (the first) | duplicate |
get next | any | 2 (the second) | — |
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 for COBOL |
---|---|---|---|
set (of the form set record position) | 1 | -- | -- |
get previous | any | 1 | -- |
The next three tables apply to EGL-generated Java code.
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value for Java |
---|---|---|---|
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 | — |
EGL statement (in order) | Key in the indexed record | Key in the file record retrieved by the statement | EGL error value for Java |
---|---|---|---|
set (of the form set record position) | 2 | — | duplicate |
get next | any | 2 (the first) | — |
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 for Java |
---|---|---|---|
set (of the form set record position) | 1 | -- | -- |
get previous | any | 1 | -- |
An SQL FETCH statement represents the EGL get previous statement in the generated code. The format of the generated SQL statement cannot be changed, except to set the INTO clause.
In general, if an error occurs and processing continues, the cursor remains open, with the cursor position unchanged.
Finally, when you specify SQL COMMIT or sysLib.commit, your code retains position in the cursor that was declared in the open statement, but only if you use the hold option in the open statement.
Related concepts
Record types and properties
Related tasks
Syntax diagram for EGL statements and commands
Related reference
add
close
delete
Exception handling
execute
get
get next
I/O error values
open
prepare
EGL statements
replace
set