COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

PROG1 /TERM $TE1.#E02/
#TEMP
The special name #TEMP represents a temporary disk file on the default volume (which is specified
by the program’s startup message). When the program opens a file that is assigned to #TEMP,
the HP COBOL run-time routines create a disk file on the default volume. When the program closes
a temporary disk file, the file system purges it. For more information about temporary disk files,
see the Guardian Programmer’s Guide.
In the program PROG1, these SELECT and ASSIGN clauses associate the COBOL file name
TEMPFILE with the special name #TEMP, which stands for the system file name that the file system
gave the temporary file.
SELECT TEMPFILE ASSIGN TO #TEMP
Equivalently, this ASSIGN command associates the COBOL file name TEMPFILE with the special
name #TEMP:
ASSIGN PROG1.TEMPFILE, #TEMP
#DYNAMIC
The special name #DYNAMIC represents the file specified with the run-time library routine
COBOL_ASSIGN_ during the execution of the current process.
If you want your HP COBOL program to accept or construct a file name and then open the file
with that name, you must:
1. Assign the COBOL file name to #DYNAMIC (in the file-control entry).
2. Associate #DYNAMIC with a system file name by calling the routine COBOL_ASSIGN_.
3. Open the file (using its COBOL file name).
Suppose that you want your program to use a file that the user specifies at run time. Following
Step 1, you assign the COBOL file name (ADJUSTABLE in this example) to the special name
#DYNAMIC in the file-control entry:
SELECT ADJUSTABLE ASSIGN TO #DYNAMIC.
To follow Step 2, you must declare Working-Storage data items to hold the name and the error
value returned by the COBOL_ASSIGN_ routine, prompt the user for a file name, and then call
the COBOL_ASSIGN_ routine:
01 ADJUSTABLE-STUFF.
03 ADJUSTABLE-NAME PICTURE X(34).
03 ADJUSTABLE-ERROR PICTURE S9(4).
. .
DISPLAY "What file shall I read?".
ACCEPT ADJUSTABLE-NAME.
ENTER "COBOL_ASSIGN_" USING ADJUSTABLE
ADJUSTABLE-NAME
GIVING ADJUSTABLE-ERROR.
IF ADJUSTABLE-ERROR = ZERO
OPEN INPUT ADJUSTABLE
ELSE
PERFORM ADJUSTABLE-ERROR-ROUTINE
...
To lock a file that has been opened with dynamic assignment, use the LOCKFILE statement. You
cannot perform a CLOSE WITH LOCK operation on such a file.
NOTE: Do not use #DYNAMIC in the TACL command ASSIGN. You will get an error when you
try to assign a system file name to the associated COBOL file name with the COBOL_ASSIGN_
routine.
For further information about the COBOL_ASSIGN_ routine, see COBOL_ASSIGN_ (page 646).
Files 835