To delete a record.
DELETE record-name [WHERE (condition) | CURRENT | KEY(Key)] [CHECKCOPY
fieldname] [RESETFUNCTION]
[NOCHILDREN(Reference
[,reference]…] [CONFIRM];
For VSAM the DELETE statement should logically follow a GET …
statement, being written within the GET block. In this situation you will omit the WHERE clause, and (in CICS programs) you may choose
to include or omit CHECKCOPY.
For SQL databases the DELETE statement can appear
anywhere, but the WHERE clause is required
(otherwise the DELETE
would delete ALL records from this table) unless CURRENT
is present.
CURRENT will cause the last record read to
be deleted. An execution-time error will
occur if there is no such record, or if the record has already been
deleted. Current is only valid for SQL data, and DELETE xxx CURRENT
statements must be written within the scope of PROCESS xxx/END PROCESS
xxx, or GET
xxx/END
GET xxx.
KEY is used like WHERE, for situations where the key value has already
been set in the record in memory (and so it would have seemed illogical to have
written DELETE
file WHERE (File.key = File.key);
CHECKCOPY is used in CICS
programs to check that the record has not been updated by another user between
the GET
for enquiry and following DELETE.
The RESETFUNCTION option is only valid in classical CICS programs. The PROGRAM statement must name the input screen with INSCREEN, and this screen must contain a message field called “Error” and a Function field defined from a Commarea field that has been defined like this: -
DEFINE CICS2C TYPE(COMMAREA) DATA(
Function CHAR(1) CODES (E:Enquiry,U:Update,A:Add,D:Delete) VALUE 'E',
…
RESETFUNCTION sets an error message and the next
function. Refer to JazzLRM_END for details.
NOCHILDREN checks for child records. If any are present, then the DELETE fails with a message. For example
DELETE Custf … NOCHILDREN (Orders);
This means
that DELETE is to fail if this customer (Custf) has any Orders.
There may
be several child-files named: for example if your system has separate files for
Open and Closed Orders, you might write a NOCHILDREN option like this: -
DELETE Custf … NOCHILDREN(OpenOrd, ClsdOrd);
Each
NoChildren reference is either a reference to another file (Orders, OpenOrd, ClstOrd) or to a field (or group) in another file (Orders.OrdCustid). When the reference is to a file then Jazz
infers the Join relationship by looking up the file’s definition. For example
DELETE Custf KEY(Custf.Account) NOCHILDREN(Orders);
looks up
the Orders definition, where it finds
DEFINE Orders VSAM DATA(
OrdNbr DECIMAL(7) DPIC '9999999' KEY HEADING 'Order Number',
OrdCustId LIKE custf.account DKEY
'ibmuser.vsam.Orders1',
ordDate CHAR(12),
OrdPart LIKE parts.partnbr DKEY
'ibmuser.vsam.Orders2' EXISTS Parts.Partnbr,
OrdQty SMALLINT,
OrdDiscount DECIMAL (6,4) HEADING 'Order Discount',
OrdField1 SMALLINT,
OrdField2 SMALLINT,
OrdStatus CHAR(10))
DSNAME 'ibmuser.vsam.Orders';
where the
first field or group defined LIKE or EXISTS referencing custf.account is OrdCustid, so NOCHILDREN(Orders) is equivalent to NOCHILDREN(Orders.OrdCustid).
With either
form of NOCHILDREN Jazz executes a GET to see if there are any record, preceding the DELETE statement with the equivalent of: -
GET orders WHERE(Orders.OrdCustId =
CustF.Account)
FIRST;
IF orders.$Found
THEN;
Owspg4.ERROR = 'Delete custf invalid: there are related orders Records';
REPLY; [This terminates the program
END IF;
END GET orders;
CONFIRM. Proposed definition, not yet
implemented: Only valid in Classical
CICS programs. If CONFIRM is present
then a message “Press Enter again to confirm delete, else cancel” is produced
when a delete is attempted, and the user must press enter again to have the delete
actually occur.