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

Libraries and Utility Routines
HP COBOL Manual for TNS/E Programs520347-003
13-68
COBOL_ASSIGN_
COBOL_ASSIGN_ does not determine whether the assigned file actually exists or is
accessible. This checking is done by the OPEN statement. COBOL_ASSIGN_ can be
called repeatedly for one fd-name.
An attempt to open a file using a dynamically assignable fd-name before
COBOL_ASSIGN_ has been used on it is an attempt to open $volume.#DYNAMIC
(where $volume is the default volume). This causes a run-time error.
A CLOSE LOCK on a file using a dynamic fd-name closes the file but does not lock
it. If locking were allowed, it would only prevent the reuse of the fd-name for the
remainder of the run unit’s existence; the file would still be accessible through another
dynamic fd-name.
A command interpreter ASSIGN command cannot designate an fd-name as
dynamically assignable—you must do this in the source program. ASSIGN can,
however, assign a default value to the previously designated dynamic file name. The
effect is the same as having an ENTER COBOL_ASSIGN_ statement as the first
statement in the program. See ASSIGN Command.
A CRE HP COBOL program can call either COBOL_ASSIGN_ (the COBOL-
environment routine) or COBOL_ASSIGN_ (the equivalent CRE routine). If it calls
COBOL_ASSIGN_, it actually calls COBOL_ASSIGN_ indirectly. There are
advantages to calling COBOL_ASSIGN_ directly (see COBOL_ASSIGN_).
Example 13-16. COBOL_ASSIGN_ Routine
IDENTIFICATION DIVISION.
...
ENVIRONMENT DIVISION.
...
SPECIAL-NAMES.
FILE "$SYSTEM.SYSTEM.COBOLLIB" IS COBOLLIB.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PARTNO ASSIGN #DYNAMIC.
DATA DIVISION.
...
WORKING-STORAGE SECTION.
01 PART-FILE-NAME PICTURE X(35).
01 ASSIGN-ERROR COMP PICTURE 9999.
PROCEDURE DIVISION.
SETUP.
DISPLAY "ENTER CHOSEN PART FILE NAME"
ACCEPT PART-FILE-NAME
ENTER "COBOL_ASSIGN_" OF COBOLLIB USING PARTNO
PART-FILE-NAME
GIVING ASSIGN-ERROR
IF ASSIGN-ERROR = 0
OPEN INPUT PARTNO
ELSE IF ASSIGN-ERROR = 1
...