EGL Reference Guide for iSeries

replace

The EGL replace statement puts a changed record into a file or database.



Syntax diagram for the replace statement

record name
Name of the I/O object: an indexed, relative, or SQL record.
with #sql{ sqlStatement }
An explicit SQL UPDATE statement. Leave no space between #sql and the left brace.
fromresultSetID
ID that ties the replace statement to a get or open statement run earlier in the same program. For details, see resultSetID.

The following example shows how to read and replace a file record:

  emp.empnum = 1;         // sets the key in record emp
 
  try
    get emp forUpdate;
  onException
    myErrorHandler(8);  // exits the program
  end
 
  emp.empname = emp.empname + " Smith";
 
  try
    replace emp;
  onException
    myErrorHandler(12);
  end

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

Indexed or relative record

If you want to replace an indexed or relative record, you must issue a get statement for the record with the forUpdate option, then issue the replace statement with no intervening I/O operation against the same file. After you invoke the replace statement, the effect of the next I/O operation on the same file is as follows:

For details on the forUpdate option, see get.

SQL record

In the case of SQL processing, the EGL replace statement results in an SQL UPDATE statement in the generated code.

You must retrieve a row for subsequent replacement, in either of two ways:

Error conditions

The following conditions are among those that are not valid when you use a replace statement:

The following situation also causes an error:

You can solve the previous mismatch in any of these ways:

Implicit SQL statement

By default, the effect of a replace statement that writes an SQL record is as follows:

The SQL statement has these characteristics by default:


Related concepts
Record types and properties
References to parts
resultSetID
Run unit
SQL support


Related tasks
Syntax diagram


Related reference
add
close
delete
EGL statements
Exception handling
execute
get
get next
get previous
I/O error values
open
prepare
SQL item properties
sysVar.terminalID


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