Previous Topic: DFNRPTFMT Device Function

Next Topic: Array DLTOBJ

DLTOBJ Database Function

The Delete Object (DLTOBJ) function defines a routine to delete a record from a database file. The DLTOBJ function includes processing to check that the record is still on the file before deleting it. You can add processing to a DLTOBJ function such as processing that performs a cascade delete of any associated records.

The DLTOBJ function does not have device files or function options. However, it has action diagram user points.

A DLTOBJ function is provided for all files. By default, it is normally inserted into the Delete DBF Record user point in all edit functions.

Note: When a DLTOBJ is inserted in the Delete DBF Record user point, code is generated to check if the record has been changed (by another user) before the record is deleted. However, if a DLTOBJ is inserted in any other user point in any function type, this checking is not generated.

The DLTOBJ function must be attached to an Update (UPD) access path, or can be attached to a Physical (PHY) access path. The primary key(s) of the UPD access path must be declared to the Delete Object function; other parameters can also be added.

Note: For more information on PHY, see the section Internal Database Functions and PHY Access Paths

The following table shows the parameters available.

Parameters

Usage

Role

Default

Option

Key fields from access path

I

-

Y

R

Other fields

Any

-

-

O

The following table shows the function options available.

Option

Default Value

Other Values

Share Subroutine

M(YSHRSBR)

N, Y

You can add your own checks to the action diagram of the DLTOBJ function to ensure that no record is deleted that is referenced elsewhere in the database, ensuring referential integrity. You would use a Retrieve Object function to check for the existence of referenced records.

For example, you can allow Customers to be deleted from the Customer file but only if the Customer is not referenced in an order on the Order file. You could modify the DLTOBJ function for the Customer file to include this check by calling a Retrieve Object function on the Order file. If an Order is found that references the Customer, the condition Error is moved to the program’s *Return code and tested on return to the Delete Object function:

> USER: Processing before DBF update :— : Retrieve object - Order * <<< : .-CASE<<< <<< : |-PGM. *Return code is Error <<< <<< : |,—QUIT<<< <<< : ,-ENDCASE<<< <<< '—