HIGH-VALUE is a COBOL figurative constant that represents the character with the highest value in the program's collating sequence. Typically this is hexadecimal X'FF' (all bits set). It is used for initializing fields to a maximum value, sentinel values in merge or search logic, comparisons, and ensuring certain records sort last. HIGH-VALUE and HIGH-VALUES are functionally identical and can be used interchangeably.
HIGH-VALUE is a figurative constant: a predefined value that means "the maximum character in the collating sequence." Key points:
HIGH-VALUE can appear in VALUE clauses, MOVE statements, and conditions:
123456789101112131415*> In VALUE clause 01 WS-FIELD-1 PIC X(10) VALUE HIGH-VALUE. *> In MOVE statement MOVE HIGH-VALUE TO WS-FIELD-2 *> In comparisons IF WS-FIELD = HIGH-VALUE DISPLAY 'Field is at maximum (e.g. sentinel)' END-IF *> Check if value is less than sentinel IF WS-KEY < HIGH-VALUE PERFORM PROCESS-RECORD END-IF
Initializing a field to HIGH-VALUE gives every character the maximum value. This is often used for sentinel or end-of-data values.
1234567891011WORKING-STORAGE SECTION. 01 WS-SENTINEL-KEY PIC X(10) VALUE HIGH-VALUE. 01 WS-END-MARKER PIC X(1) VALUE HIGH-VALUE. 01 WS-MERGE-BUFFER PIC X(80) VALUE HIGH-VALUE. PROCEDURE DIVISION. MAIN-PARA. *> Each character position contains X'FF' *> Useful when this key will sort last in a merge DISPLAY 'Sentinel key initialized to HIGH-VALUE' STOP RUN.
123456789WORKING-STORAGE SECTION. 01 WS-INPUT-KEY PIC X(20). 01 WS-SENTINEL PIC X(20). PROCEDURE DIVISION. SET-SENTINEL. MOVE HIGH-VALUE TO WS-SENTINEL *> Use WS-SENTINEL to mark end of list or end of merge STOP RUN.
Comparing against HIGH-VALUE lets you detect sentinels or ensure a value is "less than end."
1234567891011121314151617WORKING-STORAGE SECTION. 01 WS-RECORD-KEY PIC X(8). 01 WS-SENTINEL-KEY PIC X(8) VALUE HIGH-VALUE. PROCEDURE DIVISION. READ-LOOP. READ INPUT-FILE INTO WS-RECORD AT END MOVE HIGH-VALUE TO WS-RECORD-KEY END-READ *> Stop when we hit the sentinel IF WS-RECORD-KEY = HIGH-VALUE EXIT PERFORM END-IF PERFORM PROCESS-RECORD GO TO READ-LOOP.
In merge logic, one common trick is to put HIGH-VALUE in the key of an exhausted input. That key will compare greater than any real key, so that "record" never gets chosen and the merge stops when all inputs are exhausted.
12345678910111213WORKING-STORAGE SECTION. 01 MERGE-RECORD. 05 MR-KEY PIC X(10). 05 MR-DATA PIC X(70). PROCEDURE DIVISION. MERGE-EXAMPLE. *> When one input is exhausted, set its key to HIGH-VALUE *> so it never compares less than remaining inputs MOVE HIGH-VALUE TO MR-KEY MOVE SPACES TO MR-DATA *> This record will sort last; merge logic can use it as sentinel STOP RUN.
| Constant | Value | Best Use |
|---|---|---|
| HIGH-VALUE | Maximum in collating sequence (X'FF') | Sentinels, end markers, sort last, comparisons |
| LOW-VALUE | Minimum in collating sequence (X'00') | Sort first, uninitialized checks |
| SPACES | Space character | Blank text, display |
| ZEROS | Zero character or numeric zero | Numeric zero, zero-filled fields |
A sentinel is a special value that means "no more data." Using HIGH-VALUE ensures the sentinel compares greater than any real key.
Imagine lining up kids by the first letter of their name. "A" comes first, "Z" last. HIGH-VALUE is like a fake kid whose name starts with a letter that always comes after "Z"—so they always go at the very end. When your program says "give me the next smallest key," it will never pick this fake one until everyone else is done. That fake value is HIGH-VALUE: the "biggest" value so it sorts last and is easy to detect.
Write a paragraph that reads records with an 8-byte key until end-of-file, then moves HIGH-VALUE to the key and exits the processing loop when the key equals HIGH-VALUE.
Define two key fields (e.g. for two input streams). When one stream is exhausted, set its key to HIGH-VALUE. Write a loop that picks the smaller key and processes it, and stops when both keys are HIGH-VALUE.
Create a small program that initializes a PIC X(5) field with HIGH-VALUE using both a VALUE clause and a MOVE, and use IF field = HIGH-VALUE to display a message.
1. What does HIGH-VALUE represent in COBOL?
2. What is the difference between HIGH-VALUE and HIGH-VALUES?
3. How would you set a field to act as a sentinel that sorts last?
4. What is the typical hexadecimal value of HIGH-VALUE?
5. When would you use HIGH-VALUE instead of a large numeric literal?