EGL Reference Guide for iSeries

get previous

The EGL get previous statement reads the previous record in the file that is associated with a specified EGL indexed record.



Syntax diagram for the get previous statement

indexed record name
Name of the indexed record

An example 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

When a get previous statement operates on an indexed record, the effect is based on the current file position, which is set by either of these operations:

Rules are as follows:

Consider a file in which the keys in an alternate index are as follows:

  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 --


Related concepts
Record types and properties


Related tasks
Syntax diagram


Related reference
add
close
delete
Exception handling
execute
get
get next
I/O error values
open
prepare
EGL statements
replace
set


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]