Delete

PURPOSE:  The DELETE command removes records from the Data Set (DS), according to user specified criteria.  DELETE always affects the current DS.  Either deleted or not deleted records can be written to another DS.  This command applies to DB-MACH2 RDBMS applications.  The DELETE command can also operate the same as the REMOVE command.  (See Form 2).

SYNTAX

FORM 1:

DELETE [/USE/ DOMAIN name] {WHEN clause; [{IF; UNLESS} clause}]

[[APPEND] UNDELETED TO ds_name [in DBL name]]

[[APPEND] DELETED TO ds_name [in DBL name]]

[VIA clause]

[SHOWING clause]

[SET clause]

[{STOP; END} clause]

/USE/ DOMAIN name

specifies the domain of a Data Index (DI) that is to be used to select records for deletion.  All domains of the DI are automatically updated to reflect the deletions.

WHEN clause

limits deletion to records having the specified key field values when a DI is in use.  Described in detail in Chapter 7.

{IF; UNLESS} clause

Described in detail in Chapter 7.  An IF; UNLESS clause or a WHEN clause must be used.

[APPEND] 

UNDELETED TO ds_name 

[in DBL name]

causes a copy of all records not deleted to be written to the specified DS.  The output DS must already exist in the current Data Base Library (DBL) and have the same Schema Definition (SD) as the current DS.  APPEND TO adds the records onto the end of the output DS.  TO without APPEND removes all existing records in the output DS. Records that are not deleted are not affected by the SET clause.  The master DS cannot be named as the output DS.

[APPEND] DELETED

TO ds_name 

[in DBL name]

causes deleted records to be written to the specified DS.  The output DS must already exist in the current DBL and have the same SD as the current DS.  The master DS cannot be named as the output DS.

VIA clause

When a Process Module (PM) is used with DELETE, the deleted records are processed in the DETAILS section.  Records that are not deleted are processed in the UNQUALIFIED section.

SHOWING clause

is as described in Chapter 7.  In this command, the SHOWING clause shows deleted records after the SET clause has been applied.

SET clause

is as described in the next chapter.  The SET clause affects only deleted records and is only valid when the command contains either a DELETED TO or SHOWING clause.

{STOP; END} clause

is as described in the Chapter 7.

EXAMPLE

*DELETE UNLESS TITLE_CODE BEGINS WITH "CP" OR "TR"

The following command deletes all records having a reorder date earlier than the current date.  The deleted records are appended to DS OLDDATA, where the current date is DS to the field PUB_DATE.

*DELETE IF ORD_DATE LE @DATE APPEND DELETED TO OLDDATA SET @DATE TO PUB_DATE

The next command causes all records in which QTY LE 50 to be deleted, and makes those records available in the DETAILS section of Process Module PULL_QTY.  The PM could further screen and manipulate the records for output to various reports or DS’s.

*DELETE IF QTY LE 50 VIA PULL_QTY

NOTES:  UNDELETED and DELETED records cannot both go to the same output DS.

If all records are to be deleted, use the CLEAR command, which removes all records without reading them.  Whenever records are deleted from a DS, the deletions are done "in place"; that is, the records are marked as deleted.  The record information fields @QUALIFIED, @UNQUALIFIED, @RECORD and @RECORDS are automatically updated.

To reclaim space used by deleted records you can EXTRACT the data set to itself.  The default deletion method can be inhibited by specifying DISALLOW IN PLACE DELETES in the SD associated with the Data Set.

FORM 2:

DELETE object_type object_name [IN DBL dbl_name]

object_type

specifies the object type to be deleted from the DBL, and also removes any associated System File.  Multiple names are separated by commas.  Valid object types are: CM, DBL, DI, DS, FS, GS, ID, PM, SD, SF, SI.

object_name

references the specific object to be deleted.  Multiple names are separated by commas.