Concatenating files
In COBOL for Linux®, you
can concatenate multiple files by separating the individual file identifiers
with a colon (:
).
About this task
For example, the following export
command
sets the MYFILE environment variable to STL-/home/myUserID/file1
followed by STL-/home/myUserID/file2
:
export MYFILE='STL-/home/myUserID/file1:STL-/home/myUserID/file2'
The export
command together with a SELECT
and ASSIGN
clause
that associate the environment variable with a COBOL internal file-name
causes the two files to be treated as a single file in the COBOL program:
SELECT concatfile ASSIGN TO MYFILE
Concatenation is supported if the assignment-name for
the concatenation is an environment variable (as shown above), literal,
or USING
data-name.
A COBOL internal file assigned to a concatenation of file identifiers must meet the following criteria:
ORGANIZATION
isSEQUENTIAL
orLINE SEQUENTIAL
.ACCESS MODE
isSEQUENTIAL
.OPEN
statements for the file have modeINPUT
.
You can concatenate files that are in any of the file systems. You can specify the file-system ID for any or all of the file identifiers in a given concatenation. However, all file identifiers in a concatenation must specify or default at run time to the same file system, and all the files must have consistent attributes.
GDGs: You can concatenate entire generation data groups (GDGs) or individual generation files from one or more groups. If you specify a GDG in a concatenation, the most current generation file is read first, then the next most current, and so on until the least current generation file in the group is reached. It is an error to include a newly defined, and thus empty, GDG in a concatenation.
Validation of the individual file identifiers in a concatenation is deferred until the corresponding COBOL file is opened. At that time, the first identifier in the concatenation is resolved, and the open is attempted.
After
a successful OPEN
, the first file in the concatenation
can be read until its last record has been reached. At the next READ
statement,
the next file identifier in the concatenation is resolved and opened.
If all the files in
a concatenation are unavailable when an OPEN
statement
is executed for an optional COBOL file, the OPEN
is
successful and the file status key is set to 05. The first READ
operation
returns end-of-file, and the AT END
condition exists.
ASSIGN clause (COBOL for Linux on x86 Language Reference)
File concatenation (COBOL for Linux on x86 Language Reference)