replace

In the context of DL/I, the replace statement puts a changed record into a hierarchical database.

The replace statement generates a DL/I REPL statement. In DL/I, you must get and hold a segment before you can overwrite it. The EGL keywords get...forUpdate, get next...forUpdate, and get next inParent...forUpdate all hold the requested segment for replacement.

Syntax

Syntax diagram for DL/I replace statement considerations
DLISegmentVariable
Name of the DLISegment variable that corresponds to the segment to be replaced.
usingPCB pcbName
Option that specifies the name of a PCB, as defined in your PSB record, to use instead of the default PCB.
with #dli{ dliStatement }
Option that allows an explicit DL/I REPL statement, as described in #dli directive. Leave no space between #dli and the left brace.

Example

The following example overwrites an order from the customer database:
// define DLI Segment records using the hostVarQualifier property
Record CustomerRecordPart type DLISegment
{ segmentName="STSCCST", keyItem="customerNo", hostVarQualifier="myCustomer" }
...
end
Record LocationRecordPart type DLISegment
{ segmentName="STSCLOC", keyItem="locationNo", hostVarQualifier="myLocation" }
...
end
Record OrderRecordPart type DLISegment
{ segmentName="STPCORD", keyItem="orderDateNo", hostVarQualifier="myOrder" }
...
end

	//create variables for the records
	myCustomer CustomerRecordPart;
	myLocation LocationRecordPart;
	myOrder    OrderRecordPart;

	//build a segment search argument
	myCustomer.customerNo = "5001";
	myLocation.locationNo = "22";
	myOrder.orderDateNo = "20050730A003";

	//hold the requested order segment
	try
		get myOrder forUpdate;
		onException(dex DLIException)
			myErrorHandler(dex);
	end
	
	//update the information
	changeOrder(myOrder);

	//rewrite the order
	try
		replace myOrder;
		onException(dex DLIException)
			myErrorHandler(dex);
	end
The get...forUpdate statement generates qualified SSAs for customer, location, and order:
GHU STSCCST (STQCCNO = :myCustomer.customerNo) 
    STSCLOC (STQCLNO = :myLocation.locationNo) 
    STPCORD (STQCODN = :myOrder.orderDateNo)
The replace statement then simply generates the following:
REPL STPCORD

Feedback