EGL Reference Guide for iSeries

get next

The EGL get next statement reads the next record from a file or message queue, or the next row from a database.



Syntax diagram for the get next statement

record name
Name of the I/O object: an indexed, MQ, relative, serial, or SQL record.
fromresultSetID
For SQL processing only, an ID that ties the get next statement to an open statement run earlier in the same program. For details, see resultSetID.
into
Begins an EGL into clause, which lists the items that receive values from a relational-database table.
item
An item that receives the value of a particular column. Do not precede the item name with a colon (:).

An example of file access is as follows:

  try
    open record1 forUpdate;
    onException
      myErrorHandler(8);
      return;
  end
  try
    get next record1; 
    onException
      myErrorHandler(12);
      return;
  end
 
  while (record1 not endOfFile)
    makeChanges(record1); // process the record
 
    try
      replace record1; 
    onException 
      myErrorHandler(16); 
      return;
    end
 
    try
      get next record1; 
    onException
      myErrorHandler(12);
      return;
    end
  end // end while
 
  sysLib.commit();

Details on the get next statement depend on the record type. For details on SQL processing, see SQL record.

Indexed record

When a get next 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 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 two 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 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 for COBOL
set (of the form set record position) 2 no retrieval duplicate
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 --

The next two 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 2 2 (the first of three) duplicate
get next any 2 (the second) duplicate
get next any 2 (the third) --
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 for Java
set (of the form set record position) 2 no retrieval duplicate
get next any 2 (the first of three) --
get next any 2 (the second) duplicate
get next any 2 (the third) --
get next any 3 --

Message queue

When a get next operates on a MQ record, the first record in the queue is read into the MQ record. This placement occurs because the get next invokes one or more MQSeries calls:

Relative record

When a get next statement operates on a relative record, the effect is based on the current file position, which is set by a successful input or output (I/O) operation such as a get statement or another get next statement. Rules are as follows:

Serial record

When a get next statement operates on a serial record, the effect is based on the current file position, which is set by another get next statement. Rules are as follows:

It is recommended that you avoid having the same file open in more than one program at the same time.

SQL record

When a get next statement operates on an SQL record, your code reads the next row from those selected by an open statement. If you issue a get next statement to retrieve a row that was selected by an open statement that has the forUpdate option, you can do any of these:

An SQL FETCH statement represents the EGL get next statement in the generated code. The format of the generated SQL statement is as follows and cannot be changed, except to set the INTO clause:

  FETCH cursor USING DESCRIPTOR SQLDA INTO ...

If you issue a get next statement that attempts to access a row that is beyond the last selected row, EGL sets the SQL record to noRecordFound and closes the cursor.

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 in the following case:


Related concepts
Record types and properties
resultSetID
SQL support


Related tasks
Syntax diagram


Related reference
add


close
delete
Exception handling
execute
get
get previous
I/O error values
EGL statements
open
prepare
replace
set
SQL item properties


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