Previous Topic: Update Records in an NDB

Next Topic: Retrieve Records from an NDB

Delete Records from an NDB

To delete records from an NDB, use the &NDBDEL verb. The RID(s) of the record(s) to be deleted must be known. The RID is normally obtained from a preceding &NDBGET or &NDBSCAN.

To delete a record, code:

&NDBDEL dbname RID=&rid

where &rid is an NCL variable that contains the RID.

There is no direct equivalent to the &FILE DEL KEQALL/KGEALL generic delete. However, embedding an &NDBDEL in a loop controlled by an &NDBGET GENERIC or &NDBGET SEQUENCE=name allows easy deletion of any group of records (particularly powerful after an &NDBSCAN).

Example: Delete Records from an NDB

This example shows how to delete all records that have SURNAME = SMITH and STATUS = DEPARTED.

&NDBSCAN MYNDB SEQ=S1 DATA SURNAME = SMITH AND STATUS = +
                     DEPARTED
&IF   &NDBRC = 0 &DO
   &NDBGET MYNDB SEQ=S1 FORMAT NO-FIELDS
   &DOWHILE &NDBRC = 0
      &NDBDEL dbname RID=&NDBRID
      &NDBGET dbname MYNDB SEQ=S1 FORMAT NO-FIELDS
      &DOEND
&DOEND

Following the &NDBDEL, the &NDBRC system variable is set to 0 if the delete was successful, or 1 if no record with the supplied RID was found.