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.
The replace statement generates a DL/I REPL statement. In DL/I, you must get and hold a segment before overwriting it. The EGL keywords get...forUpdate, get next...forUpdate, and get next inParent...forUpdate will all hold the requested segment for replacement.
//create instances of the records myCustomer CustomerRecord; myLocation LocationRecord; myOrder OrderRecord; //build a segment search argument myCustomer.customerNo = "5001"; myLocation.locationNo = "22"; myOrder.orderDateNo = "20050730A003"; //hold the requested order segment try get myOrder forUpdate; onException myErrorHandler(2); end //update the information changeOrder(myOrder); //rewrite the order try replace myOrder; onException myErrorHandler(8); end
For details on the forUpdate option, see get.
In the case of SQL processing, the EGL replace statement results in an SQL UPDATE statement in the generated code.
UPDATE tableName
SET column01 = :recordItem01,
column02 = :recordItem02,
.
.
.
columnNN = :recordItemNN WHERE CURRENT OF cursor
Related concepts
Record types and properties
References to parts
resultSetID
Run unit
SQL support
Related tasks
Syntax diagram for EGL statements and commands