In the context of SQL, the EGL replace statement puts revised information from an SQL record variable back into a row of a relational database.
The statement produces an SQL UPDATE statement in the generated code. EGL can produce this statement implicitly, based on information and properties in your SQL record variable, or you can embed explicit SQL code in the replace statement using the #sql directive (see sql directive).

UPDATE tableName
SET column01 = :myField01,
column02 = :myField02,
...
columnNN = :myFieldNN
WHERE CURRENT OF cursor
The following code includes the replace statement. The code comes from the complete SQL program that you can find in Sample EGL SQL program.
try
get dept forupdate;
dept.description = "Test Engineers";
replace dept;
commit();
onException(sqlEx SQLException)
sqlFailure();
end
The following example shows the replace statement for Multiple Row:
employees Employee[0]{rowsetsize=10};
Open resultset1 forUpdate with #sql{
select eID, uName, PASSWORD, fName, lName, office, sex, EMail
from EMPLOYEETEST
} for employees;
Get Next employees;
//this updates the second row in the row set with current contents
employees[2].uName = “test”;
Replace employees[2];
// this updates the second row in the row set with explicit variable
newName CHAR(20) = “test1”;
Replace employees[2]
#with SQL{ update EMPLOYEETEST
set uName = :newName };
// the index can be a variable
i int = 2;
Replace employees[i];
//this updates all rows in the row set with uName = "test"
//Explicit SQL must be used, otherwise there should be a
//validation error.
uName CHAR(10) = “test”;
Replace employees
#with SQL{ update EMPLOYEETEST
set uName = :uName };
| Platform | Issue |
|---|---|
| COBOL generation | For best performance in COBOL, always include the from resultSet clause in the replace statement. |
| SQL Server | Multiple Row delete last and get last cannot be used together. The result set will be closed when both statements are executed once. |
| DB2® for i5/OS™ | Journaling must be enabled or add transation isolation=none to the connection string. |