COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-43
Purging a File From an HP COBOL Program
Purging a File From an HP COBOL Program
The HP COBOL language provides no mechanism for deleting a file from the system
directory; an HP COBOL program can purge a file only through an explicit call to the
FILE_PURGE_ procedure. The file being purged must be closed.
The FILE_PURGE_ procedure accepts the internal form of a file name as a parameter.
To determine whether the purge operation was successful, call the HP COBOL routine
COBOLFILEINFO with the file name as its parameter. COBOLFILEINFO returns an
error value. If the purge operation was successful, the error value is zero.
One common reason for a purge operation to fail is that the process’s accessor ID was
not authorized to purge the file according to the security attributes of the file.
If the reason you want to purge a file is that you want to have a temporary file for the
duration of a single process and the name of the file is not of any real interest, use the
special name #TEMP in the ASSIGN clause of the file-control entry at compilation time
(or in a TACL ASSIGN command at execution time). When you specify #TEMP, the
run-time routines create a temporary file on the process’s default volume.
You can also create a temporary file on a specific volume by just assigning the
HP COBOL file to the volume name, specifying spaces. It is often useful to locate a
temporary file on a different volume to improve performance.
The TACL ASSIGN command enables you to allocate specific primary and secondary
extents for temporary and permanent disk files that a process is to create. If you do not
specify extents, the run-time routines use a primary extent size of 4 disk pages (each
page holds 2048 bytes) and a secondary extent size of 20 disk pages.
Example 28-13. Purging a File From an HP COBOL Program
WORKING-STORAGE SECTION.
01 FS-ERROR NATIVE-2
01 EXTERNAL-NAME PIC X(30).
01 INTERNAL-NAME.
03 VOL-NAME PIC X(8).
03 SUBVOL-NAME PIC X(8).
03 FILE-NAME PIC X(8).
01 PURGE-RESULT PIC S9(4) COMP.
88 PURGED-OK VALUE ZERO.
...
PROCEDURE DIVISION.
...
MOVE "$FIFTY.NIFTY.SHIFTY" TO EXTERNAL-NAME.
MOVE "$FIFTY" TO VOL-NAME.
MOVE "NIFTY" TO SUBVOL-NAME.
MOVE "SHIFTY" TO FILE-NAME.
ENTER "FILE_PURGE_" USING EXTERNAL-NAME (1:19)
GIVING FS-ERROR.
ENTER TAL "COBOLFILEINFO" USING INTERNAL-NAME PURGE-RESULT
IF PURGED-OK
...