COBOL Tutorial

Progress0 of 0 lessons

COBOL HIGH-VALUE

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.

What is HIGH-VALUE?

HIGH-VALUE is a figurative constant: a predefined value that means "the maximum character in the collating sequence." Key points:

  • Maximum value: the highest character in the collating sequence
  • Typically X'FF': all bits set in one byte
  • Singular/plural: HIGH-VALUE and HIGH-VALUES are the same
  • Common use: sentinels, end markers, and "sort last" keys
  • Multi-character: in a PIC X(n) field, every position is set to the maximum character

Basic Syntax

HIGH-VALUE can appear in VALUE clauses, MOVE statements, and conditions:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
*> 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

Initialization with HIGH-VALUE

Initializing a field to HIGH-VALUE gives every character the maximum value. This is often used for sentinel or end-of-data values.

VALUE Clause

cobol
1
2
3
4
5
6
7
8
9
10
11
WORKING-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.

MOVE Statement

cobol
1
2
3
4
5
6
7
8
9
WORKING-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.

Using HIGH-VALUE in Comparisons

Comparing against HIGH-VALUE lets you detect sentinels or ensure a value is "less than end."

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
WORKING-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.

HIGH-VALUE in Sorting and Merging

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.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
WORKING-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.

HIGH-VALUE vs Other Constants

HIGH-VALUE vs other figurative constants
ConstantValueBest Use
HIGH-VALUEMaximum in collating sequence (X'FF')Sentinels, end markers, sort last, comparisons
LOW-VALUEMinimum in collating sequence (X'00')Sort first, uninitialized checks
SPACESSpace characterBlank text, display
ZEROSZero character or numeric zeroNumeric zero, zero-filled fields

Step-by-Step: Using HIGH-VALUE as a Sentinel

A sentinel is a special value that means "no more data." Using HIGH-VALUE ensures the sentinel compares greater than any real key.

  • Define a key field and a sentinel field (or use one field and set it to HIGH-VALUE when done).
  • Initialize the sentinel key to HIGH-VALUE (VALUE clause or MOVE).
  • When reading input, when you reach end-of-file, move HIGH-VALUE into that input's key (or set the record key to HIGH-VALUE).
  • In your loop, compare the current key to HIGH-VALUE; when equal, exit the loop.

Explain Like I'm Five: HIGH-VALUE

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.

Best Practices

  • Use HIGH-VALUE for sentinel keys in merges or sequential processing so they sort last.
  • Use it for end-of-list or end-of-data markers in character key comparisons.
  • Prefer HIGH-VALUE over a literal like X'FF' so the code stays independent of the collating sequence.
  • Document where you use HIGH-VALUE as a sentinel so maintainers know it is not real data.
  • Use with alphanumeric (PIC X) fields; for numeric "max" semantics use numeric literals or a different approach.

Common Mistakes

  • Using HIGH-VALUE in numeric fields and expecting the largest number—HIGH-VALUE is a character value, not a numeric maximum.
  • Assuming HIGH-VALUE is always X'FF' when a custom collating sequence is in effect.
  • Using HIGH-VALUE when SPACES or another marker would be clearer (e.g. for "blank" or "not set").

Practice Exercises

Exercise 1: Sentinel in a loop

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.

Exercise 2: Merge-style sentinel

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.

Exercise 3: Initialization

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.

Test Your Knowledge

1. What does HIGH-VALUE represent in COBOL?

  • The numeric value 255
  • The character with the highest value in the collating sequence
  • A space character
  • The lowest value in the collating sequence

2. What is the difference between HIGH-VALUE and HIGH-VALUES?

  • HIGH-VALUE is for single characters, HIGH-VALUES for multiple
  • There is no functional difference
  • HIGH-VALUE is newer syntax
  • HIGH-VALUES is deprecated

3. How would you set a field to act as a sentinel that sorts last?

  • MOVE SPACES TO WS-FIELD
  • MOVE HIGH-VALUE TO WS-FIELD
  • MOVE 999 TO WS-FIELD
  • MOVE ZEROS TO WS-FIELD

4. What is the typical hexadecimal value of HIGH-VALUE?

  • X'00'
  • X'20' (space)
  • X'FF' (all bits set)
  • X'30' (zero character)

5. When would you use HIGH-VALUE instead of a large numeric literal?

  • For arithmetic
  • For sentinel values or comparisons where you need the maximum character value
  • For display formatting
  • For initializing counters

Related Concepts

Related Pages