Help with deleting a record
I have an application where I read a record, perform some calculations, and then decide whether I want to delete the record or save (“rewrite”) it. The compiler gives me an error, apparently inconsistent with the MicroFocus documentation. Please advise how I can achieve my purpose.
In Micro Focus Online Documentation the rules for Deleting a record state:
- The associated file must be open in the I-O mode at the time of execution of this statement. (See the topic The OPEN Statement.)
- For files in sequential access mode, the last input-output statement executed for file-name-1 prior to the execution of the DELETE statement must have been a successfully executed READ statement. The operating system logically removes from the file the record that was accessed by that READ statement.
Here is my code:
ASSIGN TO "CLEANDATA"
ORGANIZATION IS SEQUENTIAL
ACCESS IS SEQUENTIAL.
. . .
LABEL RECORDS ARE STANDARD.
05 CLEANDATA-FIELD OCCURS 4000 PIC S9(12).
. . .
open I-O CLEANDATA.
. . .
read CLEANDATA next
at end go to 1000-EXIT.
MOVE 'N' TO W-DELETE-CLEANDATA-FLAG.
if W-DELETE-CLEANDATA-FLAG = 'Y'
DELETE CLEANDATA RECORD ==> Compiler barfs “Not allowed with SEQUENTIAL files”
else rewrite CLEANDATA-REC.
go to 1000-ENTRY.
I will be most grateful for your advice.
RE: Help with deleting a record
The DELETE statement can only be specified for files with relative or indexed organization.
If you want to stick with the Line sequential file type/organization, read your input file and for each record, write it or not to a second output file.