Easytrieve Deleting Records

Employee terminations, closed accounts, obsolete product codes—master files shrink as well as grow. Easytrieve physical delete uses WRITE file-name DELETE after a successful READ positioned the record in the file buffer. The FILE statement needs INDEXED or RELATIVE organization with UPDATE authority. Beginners confuse DELETE with dropping a DD from JCL; program DELETE removes one logical record from VSAM while the cluster remains. Operations teams often prefer logical delete—flip a status byte and filter on read—because audit and recovery policies require retained history. This page teaches WRITE DELETE syntax, READ-then-delete workflow, transaction-driven maintenance from driver files, STATUS and FILE-STATUS handling, contrast with UPDATE and ADD, sequential file limitations, logical-delete alternative patterns, and JCL disposition concerns when multiple jobs touch the same KSDS. Pair with the WRITE statement tutorial for statement-level detail and with indexed file processing for VSAM concepts.

Progress0 of 0 lessons

WRITE DELETE Syntax

text
1
WRITE output-file-name DELETE [STATUS]

Format 2 has no ADD, UPDATE, or FROM clauses. DELETE always targets the current active record for output-file-name—the record last successfully read into that file's buffer. STATUS optionally sets the file's FILE-STATUS field after the operation for numeric comparison.

Minimal Delete Example

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
FILE KSDS-FILE INDEXED UPDATE WHO 1 5 N PHONE 6 10 N JOB INPUT KEYS NAME DELETE-DEMO READ KSDS-FILE KEY WHO STATUS IF KSDS-FILE:FILE-STATUS NE 0 DISPLAY 'READ FAILED KEY=' WHO GOTO JOB END-IF WRITE KSDS-FILE DELETE STATUS IF KSDS-FILE:FILE-STATUS NE 0 DISPLAY 'DELETE FAILED KEY=' WHO STOP END-IF

Input file KEYS supplies WHO values to delete. Each iteration READs by key; failure skips delete with GOTO JOB to next driver record. Success issues WRITE DELETE; non-zero status STOPs the job for operator attention on production masters.

Delete Prerequisites

Checklist before coding DELETE
RequirementWhere setWhy it matters
FILE UPDATELibrary FILEAuthorizes WRITE DELETE
INDEXED or RELATIVEFILE organizationQSAM lacks random delete
Prior READ successJOB activityEstablishes current record
JCL exclusive accessDD DISPPrevent concurrent corrupting updates

Transaction-Driven Delete Pattern

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FILE TRANS FB(80) TRANS-KEY 14 3 A TRANS-CODE 17 1 A FILE PAYVS INDEXED UPDATE PAY-KEY 1 3 A JOB INPUT TRANS NAME VSAM-DELETE IF TRANS-CODE = 'D' READ PAYVS KEY TRANS-KEY STATUS IF PAYVS:FILE-STATUS EQ 0 WRITE PAYVS DELETE STATUS PERFORM WRITE-STAT-CHECK ELSE DISPLAY 'KEY NOT FOUND ' TRANS-KEY END-IF END-IF

Broadcom's Activity Section example uses TRANS-CODE D to mean delete. Only matching transactions touch the master. PERFORM WRITE-STAT-CHECK centralizes post-DELETE validation. U codes might UPDATE; A codes might ADD—single driver file orchestrates mixed maintenance.

Physical DELETE Versus Logical Delete

Delete strategies compared
StrategyMechanismWhen to use
Physical DELETEWRITE file DELETERecord must vanish from VSAM; rebuild backups exist
Logical deleteMOVE inactive flag; READ filters IF STATUS NE inactiveAudit retention; undo window; regulatory hold
Archive then deletePUT to history file then WRITE DELETEOperations wants cold storage copy before removal

Financial and HR systems often ban physical DELETE without archive. Easytrieve makes physical delete easy—governance decides which pattern is allowed. Document shop standards before coding WRITE DELETE on shared masters.

DELETE Versus UPDATE

UPDATE rewrites the current record image in place—same key, new field values. DELETE removes the record entirely; subsequent READ by that key returns not-found status. Accidentally coding UPDATE when DELETE was intended leaves obsolete rows searchable. Accidentally coding DELETE when a status flag update was intended removes recoverable data. Code reviews should verify transaction code mapping tables.

Error Handling and Idempotency

Re-running a delete job against the same driver file may attempt DELETE on keys already removed. READ returns not-found; branch to log already deleted rather than failing the batch. Idempotent delete jobs display counts: deleted, not found, errors. FILE-STATUS codes vary by access method—maintain a shop cheat sheet for 00 success versus key not found versus authority failure.

Sequential and ESDS Considerations

WRITE DELETE documentation centers on indexed and relative files. ESDS entries may support delete in VSAM depending on cluster definition; confirm with storage administrators. Standard sequential output files use PUT append—never WRITE DELETE. When unsure, treat non-KSDS files as logical-delete-only in Easytrieve programs.

Common Delete Mistakes

  • WRITE DELETE without prior successful READ.
  • Missing FILE UPDATE on the master file.
  • Ignoring FILE-STATUS after DELETE.
  • Physical delete when policy requires logical flag only.
  • SHR disposition while another job updates the same cluster.
  • Deleting wrong record after READ used stale key from unparsed transaction buffer.

Explain It Like I'm Five

Deleting a record is pulling one card out of a filing box and throwing it away. You have to find the right card first with READ—that is you read the label on the card. Then WRITE DELETE means toss that exact card. If you grab the wrong card first, you might throw away the wrong person's information, so you always check the librarian's okay number afterward. Sometimes the grown-ups do not throw cards away—they just draw a red X on the card and put it back, which is logical delete.

Exercises

  1. Write READ KEY plus WRITE DELETE with STATUS for a five-byte numeric key.
  2. Add branch when READ fails because key was already deleted.
  3. Design logical delete using STATUS-FLAG instead of WRITE DELETE.
  4. Sketch archive-then-delete with PUT to HISTFILE before DELETE.
  5. List four FILE and JCL prerequisites for safe production DELETE.

Quiz

Test Your Knowledge

1. The Easytrieve verb that deletes an indexed record is:

  • WRITE file DELETE
  • DELETE file RECORD
  • REMOVE file KEY
  • CLOSE file DELETE

2. Before WRITE DELETE you must:

  • Successfully READ the record to delete
  • PRINT the record
  • SORT the file
  • CODE TITLE

3. FILE must include UPDATE when deleting because:

  • DELETE is file maintenance requiring update authority
  • DELETE is report only
  • UPDATE is optional
  • DELETE uses TABLE

4. A transaction file with code D typically triggers:

  • READ master by key then WRITE DELETE
  • PUT append only
  • REPORT SUMMARY
  • SCREEN REFRESH

5. Non-zero FILE-STATUS after DELETE should:

  • Branch to error handling—never assume delete succeeded
  • Be ignored
  • Stop JCL only
  • Retry DELETE without READ
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 WRITE DELETESources: Broadcom Easytrieve 11.6 WRITE Statement, Indexed Files, Activity Section I/OApplies to: Easytrieve record deletion on indexed files