This phrase specifies that records are to be processed in an ascending
or descending sequence (depending on the phrase specified), based on the specified
merge keys.
- data-name-1
- Is a key data-name. Records are processed in ascending or descending
order on this key.
Data-name-1 specifies the KEY data item on which the merge is based. Each
such data-name identifies a data item in a record associated with file-name-1.
The data-names following the word KEY are listed from left to right in the
MERGE statement in order of decreasing significance without regard to how
they are divided into KEY phrases. The left-most data-name is the major key,
the next data-name is the next most significant key, and so forth.
The following rules apply:
- A specific KEY data item must be physically located in the same position
and have the same data format in each input file; however, it need not have
the same data-name.
- If file-name-1 has more than one record description, the KEY data items
need be described in only one of the record descriptions.
- If file-name-1 contains variable-length records, all of the KEY data-items
must be contained within the first n character positions
of the record, where n equals the minimum record size
specified for file-name-1.
- KEY data items must not contain an OCCURS clause or be subordinate to
an item that contains an OCCURS clause.
- KEY data items can be qualified, but they cannot be subscripted or indexed.
- KEY data items cannot be variably-located.
IBM Extension
- KEY data items can be floating-point or date-time items.
- KEY data items can be reference modified, but they cannot be subscripted
or indexed.
End of IBM Extension
- The total length (in bytes) of the KEY data items must not exceed 2 000
- Variable length fields can not be used in a MERGE key as a variable length
field. Variable length fields are converted into group items by ILE COBOL. Since
variable length fields are converted into group items, they are compared as
alphanumeric data items when used in a MERGE key.
The direction of the merge operation depends on the specification of the
ASCENDING or DESCENDING keywords as follows:
- When ASCENDING is specified, the sequence is from the lowest key value
to the highest key value.
- When DESCENDING is specified, the sequence is from the highest key value
to the lowest.
- If the KEY data item is alphabetic, alphanumeric, alphanumeric-edited,
or numeric-edited, the sequence of key values depends on the collating sequence
used (see COLLATING SEQUENCE Phrase below). If the KEY data item is DBCS or DBCS-edited,
the sequence of key values is based on a binary collating sequence of the
hexadecimal values of the DBCS characters. The COLLATING SEQUENCE phrase is
ignored.
IBM Extension
- If the KEY is an external floating-point item, the key is treated as alphanumeric.
The sequence in which the records are merged depends on the collating sequence
used.
- If the KEY is an internal floating-point item, the sequence of key values
is in numeric order.
- If the KEY is a date-time item, only some formats will be sorted as date
or time items. ILE COBOL supports many more date-time formats than IBM® i DDS.
In general, ILE COBOL date-time formats that match an IBM i DDS format are sorted
as a date or time item; all other formats are treated as alphanumeric items,
and are sorted based on their hexadecimal value.
End of IBM Extension
The key comparisons are performed according to the rules for comparison
of operands in a relation condition (see Relation Condition).