Table of contents



Official Content

Deletes the record(s) in the Base Table associated with the group where this command is specified.

Syntax

Delete

Scope

Objects: Procedure

Description

This command is used to delete records in the Base Table associated with the group where the Delete command itself is specified.

This command can only be used in a For Each command defined in a Procedure. The deletion is executed at the exact moment it is found, unless the For each command has a Blocking clause. In this last case, the current deletion will happen when the entire block is completed and the Delete command is sent to the DBMS for a bulk deletion.

Notes:

  • Referential Integrity is NOT automatically checked when the Delete command is specified.

    • If the Delete command is specified in a group that has nested groups, data in the current group can still be used in the inner nested groups despite having been physically deleted.

  • Remember to delete the inner levels first, before the outer levels. This avoids any possible cancellations or locks.

Samples

Given the Transaction objects:

PurchaseOrder
{
  PurchaseOrderId*
  PurchaseOrderDate
  SupplierId
  PurchaseOrderAmount
}

PurchaseOrderDetail
{
  PurchaseOrderId*
  PurchaseOrderDetailId*
  PurchaseOrderDetailQuantity
  PurchaseOrderDetailPrice
  PurchaseOrderDetailAmount
}

1) In the following example, purchase order lines are deleted before the purchase order header. So, there would be no purchase order lines left without a header if the program were to cancel.

For each PurchaseOrder           //As the base trn is PurchaseOrder the deletion will be perfomed in the PurchaseOrder table
   For each PurchaseOrderDetail  //As the base trn is PurchaseOrderDetail the deletion will be perfomed in the PurchaseOrder table
         Delete
   Endfor
   Delete
EndFor
To learn how to improve the throughput of bulk deletions, see Blocking clause in a 'For each' command or the general concept on Blocking Data Updates.
2) The following example, deletes a specific purchase order received by parameter.
Procedure Rule:
Parm(&PurchaseOrderId);

Procedure Source:
For each PurchaseOrder   //As the base trn is PurchaseOrder the deletion will be perfomed in the PurchaseOrder table 
    where PurchaseOrderId=&PurchaseOrderId
    For each PurchaseOrderDetail //As the base trn is PurchaseOrderDetail the deletion will be perfomed in the PurchaseOrder table 
        Delete 
    Endfor 
    Delete 
EndFor 

See Also

Database update through procedures

Videos

Start Video Updating with procedure-specific commands. Introduction

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant