version 11 (Modified)
DELETE SUBRECORD (subtable)
Parameter | Type | Description | |
subtable | Subtable | Subtable from which to delete the current subrecord |
Compatibility note: Subtables are no longer supported starting with version 11 of 4D. A compatibility mechanism ensures the functioning of this command in converted databases; however, it is strongly recommended to replace any subtables with standard related tables.
Description
DELETE SUBRECORD deletes the current subrecord of subtable. If there is no current subrecord, DELETE SUBRECORD has no effect. After the subrecord is deleted, the current subselection for subtable is empty. As a result, DELETE SUBRECORD can't be used to scan through a subselection and delete selected subrecords.
The deletion of subrecords is not permanent until the parent record is saved. Deleting a parent record automatically deletes all its subrecords.
To delete a subselection, create the subselection you want to delete, delete the first subrecord, create the subselection again, delete the first subrecord, and so on.
Examples
1. The following example deletes all the subrecords of a subtable:
ALL SUBRECORDS([People]Children) While (Records in subselection([People]Children)>0) DELETE SUBRECORD([People]Children) ALL SUBRECORDS([People]Children) End while
2. The following example deletes the subrecords in which the age of the child is greater than or equal to 12, from the [People]Children subtable :
ALL RECORDS([People]) ` Select all the records For ($vlRecord;1;Records in selection([People])) ` For all the records in the table ` Query all records that have subrecords with the criteria QUERY SUBRECORDS([People]Children;[People]Children'Age>=12) ` Loop until no subrecords are left by the query While (Records in subselection([People]Children)>0) ` Delete the subrecord DELETE SUBRECORD([People]Children) ` Query again QUERY SUBRECORDS([People]Children;[People]Children'Age>=12) End while SAVE RECORD([People]) ` Save the parent record NEXT RECORD([People]) End for
See Also
ALL SUBRECORDS, QUERY SUBRECORDS, Records in subselection, SAVE RECORD.