delete considerations for DL/I

In the context of DL/I, the delete statement removes a segment from a hierarchical database.

The delete statement generates a DL/I DLET statement. In DL/I, you must get and hold a segment before you can delete it. Use the EGL get statement in combination with the forUpdate option before using the delete statement.

The following example shows the forUpdate option:

  if (userRequest == "D")
    try
      get myRecord forUpdate;
      onException(dex DLIException) 
        myErrorHandler(dex);   // exits the program
    end

    try
      delete myRecord;
      onException(dex DLIException) 
        myErrorHandler(dex);
    end
  end

Syntax

Syntax diagram for delete considerations for DL/I
DLISegmentVariable
Name of the DLISegment variable that corresponds to the segment being deleted
usingPCB pcbName
Option to specify the name of a PCB, as defined in your PSB record, to replace the default PCB.
with #dli{ dliStatement }
Option to make an explicit DL/I DLET call; see #dli directive. Leave no space between #dli and the left brace.

Example

The following example deletes an order from the customer database:
Record CustomerRecord type DLISegment
  { segmentName="STSCCST", keyItem="customerNo", hostVarQualifier="myCustomer" }
  ...
end
Record LocationRecord type DLISegment
  { segmentName="STSCLOC", keyItem="locationNo", hostVarQualifier="myLocation" }
  ...
end
Record OrderRecord type DLISegment
  { segmentName="STPCORD", keyItem="orderDateNo", hostVarQualifier="myOrder" }
  ...
end

	//create variables for the records
	myCustomer CustomerRecord;
	myLocation LocationRecord;
	myOrder    OrderRecord;

	//build a segment search parameter
	myCustomer.customerNo = "005001";
	myLocation.locationNo = "000022";
	myOrder.orderDateNo = "20050730A003";

	//hold the requested order record
	try
		get myOrder forUpdate;
		onException(dex DLIException)
			myErrorHandler(dex);
	end
	
	//delete the order
	try
		delete 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 delete statement then generates a single line of code:
DLET STPCORD

Feedback