ASSIGN clause

The ASSIGN clause associates an internal file-name in a COBOL program with a system file-name.

assignment-name-1
Can be specified either as a user-defined word or as an alphanumeric literal. Both forms consist of up to three components, separated by hyphens. From left to right:
  1. An optional comment string
  2. An optional file-system ID
  3. A required external file-name if assignment-name-1 was specified as a user-defined word; a required system file-name if assignment-name-1 was specified as a literal

For further details about how the external file-name component of assignment-name-1 is determined, see Assignment name for user-defined words and literals.

User-defined word
assignment-name-1 must follow the rules for a COBOL word, and can be up to 30 single-byte characters in length. The user-defined word cannot be the same as a reserved word, but can be the same as any other user-defined word in the program, including the name of a data item. The external file-name component is treated at run time initially as the name of an environment variable; then, if the environment variable is not set, or is set to the empty string, the component is treated directly as the system file-name:
  • External file-name: Each time a COBOL file is opened, the external file-name is used as the name of an environment variable. If the environment variable is set to a nonempty value, the value is treated as the system file-name, or as the system file-name preceded by a file-system ID. For details, see Assignment name for data-names and environment variables. If a file-system ID is specified in the user-defined word and also in the environment variable, the environment variable takes precedence. For more information about file-system precedence, see Precedence of file-system determination in the COBOL for AIX Programming Guide.
  • System file-name: If the environment variable indicated by the external file-name is not set, the user-defined word is treated as either:
    • The system file-name
    • The system file-name preceded by a file-system ID
    • The system file-name preceded by a file-system ID preceded by a comment
    For details, see Assignment name for user-defined words and literals.
Literal
assignment-name-1 must follow the rules for a COBOL alphanumeric literal. All characters specified within the literal delimiters are used without any mapping. No check is made at run time for the existence of an environment variable. For details, see Assignment name for user-defined words and literals.
USING data-name-9
Must be defined in the working-storage section as a data item of category alphanumeric, and must not be subordinate to the file description for file-name-1. The content of data-name-9 is evaluated each time the file is opened to determine the assignment information. As for an environment variable value, the assignment information is treated as the system file-name, or as the system file-name preceded by a file-system ID. For details, see Assignment name for data-names and environment variables.