File concepts and terminology
The following concepts and terminology are used in COBOL for Linux® information about files.
- System file-name
- The name of a file on a hard drive or other external medium. A
system file-name might be qualified by a path or other prefix to ensure
uniqueness. A file exists within a specific file system.
File systems usually provide commands to manage files. The following example shows use of the
ls
command to print details about a file Transaction.log in the STL file system, and shows the system response:> ls -l Transaction.log -rw-r--r-- 1 cobdev cobdev 6144 May 27 17:29 Transaction.log
- Internal file-name
- A user-defined word that is specified after the
FD
keyword in a file description entry in theFILE SECTION
, and is used inside a program to refer to a file.In the following example,
LOG-FILE
is an internal file-name:Data division. File section. FD LOG-FILE. 01 LOG-FILE-RECORD.
Programs operate on internal files by using I/O statements such as
OPEN
,CLOSE
,READ
,WRITE
, andSTART
. As the term suggests, an internal file-name has no meaning outside a program.The
ASSIGN
clause, described below, is the mechanism that associates an internal file-name with a system file-name. - File-system ID
- A three-character string that specifies the file system in which a file is stored and through which it is accessed.
- External file-name
- A name that acts as an intermediary between an internal file-name
and the associated system file-name. The external file-name is visible
outside a program and is typically used as the name of an environment
variable that is set to the file-information (an optional
file-system ID followed by the system file-name) before the program
is run.
(An external file-name is distinct from the name of an external file, that is, a file that is defined with the
EXTERNAL
keyword in itsFD
entry.)
The ASSIGN
clause associates an internal file-name
to a system file-name, and is specified in the FILE-CONTROL
paragraph.
The ASSIGN
clause has three basic forms:
-
SELECT internal-file-name ASSIGN TO user-defined-word
-
SELECT internal-file-name ASSIGN TO 'literal'
-
SELECT internal-file-name ASSIGN USING data-name . . . MOVE file-information TO data-name
user-defined word and literal each consist of up to three components, separated by hyphens. From left to right:
- (Optional) Comment
- (Optional) File-system ID
- External file-name if a user-defined word was specified; system file-name if a literal was specified
file-information consists of at most two components, separated by a hyphen. From left to right:
- (Optional) File-system ID
- System file-name