MERGE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
MERGE Statement
The MERGE statement combines two or more identically sequenced files on a
set of specified keys. As part of the merge operation, it makes records
available in their merged order to an output procedure or an output file.
The records are made available following the actual merging of the files.
The output procedure or the moving of records to an output file is
considered part of the merge process.
MERGE statements may appear anywhere within the PROCEDURE DIVISION except
in the declaratives portion or in an input or output procedure associated
with a SORT or MERGE statement.
Syntax
Parameters
file-name-1 sort/merge file, and is described in a sort/merge file
description (SD level) entry in the DATA DIVISION.
data-name-1 data items described in records associated with
file-name-1. Each may be qualified and may vary in
length. None of these data names can be described by an
entry either containing an OCCURS clause, or subordinate
to an entry containing such a clause. If file-name-1
has more than one record description, then the data
items represented by the data names need be described in
only one of the record descriptions.
alphabet-name either EBCDIC, STANDARD-1, NATIVE, or an alphabet name
as defined by you in the SPECIAL-NAMES paragraph of the
ENVIRONMENT DIVISION.
language-name alphanumeric data item containing the name of the
language whose collating sequence should be used. This
parameter is an HP extension to the ANSI COBOL standard.
language-id integer data item containing the identification number
of the language to use. This parameter is an HP
extension to the ANSI COBOL standard.
file-name-2 files to be merged. These files must not be open at the
file-name-3 time the MERGE statement is executed. Each must be a
file described in an FD level file description in the
DATA DIVISION. No more than one such file name can name
a file from a multiple file reel. Any given file name
can be used only once in any given MERGE statement.
The actual size of the logical record or records
described for these files must be equal to the actual
size of the logical record or records described for
file-name-1. If the data descriptions of the elementary
items that make up these records are not identical, it
is your responsibility to describe the corresponding
records in such a way as to cause an equal number of
character positions to be allocated for the
corresponding records.
procedure-name- name of the first paragraph or section in an output
1 procedure.
procedure-name- name of the last paragraph or section in an output
2 procedure.
file-name-4 names of output files. These files are subject to the
same restrictions as file-name-2.
Description
The words THROUGH and THRU are equivalent, and can be used
interchangeably.
The MERGE statement merges all records contained in the files named in
the USING phrase. The files to be merged are automatically opened and
closed by the merge operation with all implicit functions performed, such
as the execution of any associated USE procedures. The files described
by file-name-2 and file-name-3 must not be open when the MERGE verb is
executed, and may not be opened or closed during an output procedure if
one is specified.
Following the actual merging of the files, but before they have been
closed, the merged records are released in the order in which they were
merged. They are released to either the specified output procedure or
the specified output file.
The results of a merge operation are predictable only when the records in
the files to be merged are ordered as described in the ASCENDING or
DESCENDING KEY phrase associated with the MERGE statement.
The data names following the word KEY are listed from left to right in
order of decreasing significance. This decreasing significance is
maintained from KEY phrase to KEY phrase. Thus, in the format shown,
data-name-1 is the most significant, and each successive data name is the
next most significant.
When the MERGE statement is executed, the records of file-name-2 and
file-name-3 are merged in the specified order (ASCENDING or DESCENDING)
using the most significant key data item. Within the records having the
same value for the most significant key data item, the records are merged
according to the next most significant key data item; this kind of
merging continues until all key data items named in the MERGE statement
have been used.
When the ASCENDING phrase is used, the merged records are in a sequence
starting from the lowest value of the key data items and ending with the
highest value.
When the DESCENDING phrase is used, the merged records are in a sequence
from the highest value of the key data item to the lowest.
Merging takes place using the rules for comparison of operands of a
relation condition. If all corresponding key data items of records to be
merged are equal, the records are written to file-name-4, or returned to
the output procedure, in the order that the input files are specified in
the MERGE statement.
COLLATING SEQUENCE Phrase
The COLLATING SEQUENCE phrase allows you to specify what collating
sequence to use in the merging operation. This phrase is optional. The
program collating sequence is used if none is specified in the MERGE
statement.
See the alphabet clause of the SPECIAL-NAMES paragraph for information on
defining and using collating sequences.
Refer to the Native Language Support Reference Manual for details about
language names and language id's.
GIVING and OUTPUT PROCEDURE Phrases
You must specify either the GIVING or OUTPUT PROCEDURE phrase in a MERGE
statement.
If you specify the GIVING phrase, all merged records are automatically
written to one or more occurrences of file-name-4. Files named in the
GIVING phrase can be sequential, relative, or indexed.
If you use the OUTPUT PROCEDURE phrase, there are several rules you must
follow in writing the procedure.
The procedure must consist of one or more paragraphs or sections that
appear contiguously in the source program, and that are not part of any
other procedure.
Since the RETURN statement is the means of making sorted or merged
records available for processing, at least one such statement must appear
in the procedure. The procedure may consist of any procedures needed to
select, modify, or copy records. The records are returned one at a time
in merged order from file-name-1.
Control must not be passed to a sort/merge output procedure except during
the execution of a SORT or MERGE statement. The procedure itself can
contain no SORT or MERGE statements, nor can it contain any explicit
transfers of control to points outside its bounds; ALTER, GO TO, and
PERFORM statements in the output procedure must refer to procedure names
within the bounds of the output procedure. Note that implied transfers
of control to declarative procedures are permitted. Thus, for example, a
WRITE statement without an AT END phrase is permitted, and will transfer
control to some associated declarative procedure if an AT END condition
occurs.
The remainder of the PROCEDURE DIVISION must not contain any transfers of
control to points inside sort/merge output procedures. No ALTER, GO TO,
or PERFORM statements outside an output procedure can refer to procedure
names within the output procedure.
When an output procedure is specified in a MERGE statement, the output
procedure is executed as part of the merge operation. The procedure is
used after the records have been merged.
At compile-time, the compiler inserts a return mechanism at the end of
the last section in the output procedure. When this return mechanism is
reached, the merge operation is terminated, and control passes to the
next executable statement following the MERGE statement.
Segmentation Considerations
The following restrictions apply to the MERGE statement when it is used
in a segmented program.
If the MERGE statement appears in a section whose segment number is less
than 50, any output procedure named in the MERGE statement must either be
totally contained within a segment (or segments) whose segment number (or
numbers) is less than 50 or be wholly contained in a single segment whose
segment number is greater than 49.
If the MERGE statement appears in a section whose segment number is
greater than 49, any output procedure referenced by the MERGE statement
must either be entirely contained within the same segment or be entirely
contained within segments whose segment numbers are less than 50.
MPE/iX 5.0 Documentation