Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cobol - is it possible to delete records in Sequential file?

I need to delete first x rows and I need to do it via Cobol. Is it possible? It seems the DELETE statement is for VSAM files only?

like image 294
Cobol4ever Avatar asked Dec 11 '25 13:12

Cobol4ever


1 Answers

You say you must do this via COBOL but do not provide a reason. Typically this type of operation is done via your shop's SORT utility. Mainframe SORT utilities normally include sophisticated record selection criteria.

Yes it is possible to do this with COBOL. You are correct in your implied statement that DELETE is for VSAM only. For a sequential file, you must read the entire file, ignoring the first x records, and write the rest to a new output file. I would suggest writing your COBOL code such that it accepts a parameter indicating how many records (x in your example) to ignore, exiting with a specific return code if there are less than x records in the file.

If you desire, you can use the C runtime routines (fopen, fread, fwrite, fclose) for file I/O to make your program generic and not specific to one particular file. COBOL requires the LRECL to be known at compile time, the C runtime routines, directly callable from COBOL via the grace of Language Environment (LE), remove this requirement.

To reiterate: this is typically done with your shop's SORT utility.

like image 176
cschneid Avatar answered Dec 14 '25 22:12

cschneid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!