COBOL How to delete a file?

Post Reply

Topic author
fim
Active Contributor
Posts: 31
Joined: Wed Jan 04, 2023 5:14 am
Reputation: 0
Status: Offline

COBOL How to delete a file?

Post by fim » Sat Feb 04, 2023 10:23 am

How to delete a file in COBOL?
/Fim W


sms
Master
Posts: 317
Joined: Fri Aug 21, 2020 5:18 pm
Reputation: 0
Status: Offline

Re: COBOL How to delete a file?

Post by sms » Sat Feb 04, 2023 3:05 pm

Code: Select all

> How to delete a file in COBOL?

   Never having written a COBOL program, I know nothing, but the "VSI
COBOL for OpenVMS User Manual"
( https://docs.vmssoftware.com/docs/vsi-cobol-for-openvms-user-guide.pdf )
Section 8.3.2, "Using File Protection" says:

o DELETE--Permits deletion of the file and is therefore not applicable
  to a VSI COBOL program (since VSI COBOL has no delete file facility)
  except through system service routines.

   I also don't know the best way to delete a file using (RMS) system
services, but I'd guess that you could use $OPEN to open the file, set
the FAB$V_DLT bit in the FAB, and then use $CLOSE to close/delete it. 
(Fortran CLOSE has a DISPOSE=DELETE option to do this, for example,
which makes it sound to me as if CLOSE is a popular place to do this
kind of thing.)

   Or, perhaps easier, LIB$DELETE_FILE.

      HELP RTL_ROUTINES LIB$ LIB$DELETE_FILE

   Chapter 13, "Using VSI COBOL in the Alpha or VAX Common Language
Environment" in the User Manual seems to deal with (Section 13.4)
"Calling Routines".

   To me, it all looks like even less fun than pure COBOL, but there are
some examples in the User Manual.


abrsvc
Contributor
Posts: 10
Joined: Wed Apr 01, 2020 8:12 am
Reputation: 0
Status: Offline

Re: COBOL How to delete a file?

Post by abrsvc » Sat Feb 04, 2023 5:57 pm

There is a lack of context here. There are a number of ways to delete a file using a COBOL program. One can use LIB$SPAWN service to create a subprocess and feed it a command string to delete a file for example. One could use the LIB$DO_COMMAND service and again provide a DCL command string. As Steve suggested, if the file is a temporary one, you can specify that the file is deleted on close.

The bottom line here is what are you really trying to accomplish? Please provide some details about what you are trying to do around this delete function. With that, we can supply a more applicable response.

Dan


Topic author
fim
Active Contributor
Posts: 31
Joined: Wed Jan 04, 2023 5:14 am
Reputation: 0
Status: Offline

Re: COBOL How to delete a file?

Post by fim » Sun Feb 05, 2023 4:24 am

Thanks.
LIB$DELETE_FILE works great in this context.
MOVE "TEST.TXT" TO FILENAME.
CALL "LIB$DELETE_FILE" USING BY DESCRIPTOR FILENAME GIVING RESPONSE.
I had missed the function when I checked the manual.

/Fim W.

Post Reply