DELETE (Delete Record)
Free-Form Syntax | DELETE{(EHMR)} {search-arg} name |
Code | Factor 1 | Factor 2 | Result Field | Indicators | ||
---|---|---|---|---|---|---|
DELETE (E) | search-arg | name (file or record format) | NR | ER | _ |
The DELETE operation deletes a record from a database file. The file must be an delete-capable file (identified by specifying *UPDATE or *DELETE in the USAGE keyword of a free-form definition, or by a U in position 17 of a fixed-form file description specification). The deleted record can never be retrieved.
If a search argument (search-arg) is not specified, the DELETE operation deletes the current record (the last record retrieved). The record must have been locked by a previous input operation (for example, CHAIN or READ).
The search argument, search-arg, must be the key or relative record number used to retrieve the record to be deleted. If access is by key, search-arg can be a single key in the form of a field name, a named constant, a figurative constant, or a literal.
If the file is an externally-described file, search-arg can also be a composite key in the form of a KLIST name, a list of values, or %KDS. Graphic and UCS-2 key fields must have the same CCSID as the key in the file. For an example of %KDS, see the example at the end of %KDS (Search Arguments in Data Structure). If access is by relative record number, search-arg must be an integer literal or a numeric field with zero decimal positions. For an example of using a list of values to search for the record to be deleted, see Figure 2.
The name operand must be the name of the update file or a record format in the file from which a record is to be deleted. A record format name is valid only with an externally described file. If search-arg is not specified, the record format name must be the name of the last record read from the file; otherwise, an error occurs.
If search-arg is specified, positions 71 and 72 can contain an indicator that is set on if the record to be deleted is not found in the file. If search-arg is not specified, leave these positions blank. This information can also be obtained from the %FOUND built-in function, which returns '0' if no record is found, and '1' if a record is found.
To handle DELETE exceptions (file status codes greater than 1000), either the operation code extender 'E' or an error indicator ER can be specified, but not both. For more information on error handling, see File Exception/Errors.
Under the IBM® i operating system, if a read operation is done on the file specified in file-name after a successful DELETE operation to that file, the next record after the deleted record is obtained.
See Database Null Value Support for information on handling records with null-capable fields and keys.
For more information, see File Operations.
- Operation code extenders H, M, and R are allowed only when the search argument is a list or is %KDS().
- Leave positions 75 and 76 blank.