ENTMF 

Comparisons of Dynamic-Length Elementary Items

General Format:

Dynamic Length Comparisons

General Rules:

  1. A comparison of two dynamic-length elementary items in a relational condition compares their current lengths, then followed possibly by a comparison of their contents in line with the following rules:
    1. If the dynamic-length elementary items are of equal length, their contents are compared as if they were operands of equal size for two fixed-length items.
    2. If the dynamic-length elementary items are of unequal length, the longer of the two items is considered the greater operand regardless of contents of either operand.
  2. If comparing a dynamic-length elementary item to a fixed-length item, the dynamic-length elementary item is handled as though it were a fixed-length item whose length is equal to the current length of the dynamic-length elementary item.

Example

Taking the following two dynamic-length elementary items:

01 color1 PIC X DYNAMIC.
01 color2 PIC X DYNAMIC.

You can compare the two items as follows:

MOVE "gray " to color1.
MOVE "gray" to color2.
IF color1 IS EQUAL TO color2 THEN
   DISPLAY "color match"
ELSE
   DISPLAY "color mismatch"
END-IF.

The result is a 'color mismatch' as the length of color1 (dynamically set to 5 at run time) differs from that of color2. As the lengths are determined to be different, the contents of the two items are not inspected.