HIGH-VALUES and LOW-VALUES
Overview
This article explains how to use HIGH-VALUES and LOW-VALUES constants in COBOL programming to represent infinitely high or low values.
Practical Application: File Merging
The guide demonstrates a practical use case: merging two files sorted by surname as the primary key.
Data Structure
FD FILE-1.
01 RECORD-1.
03 IN-NAME-1 PIC X(20).
03 FILLER PIC X(50).
FD MERGE-FILE.
01 RECORD-OUT PIC X(70).
Processing Logic
- Reads records from both files sequentially
- When EOF is reached on either file, sets that file's name field to
HIGH-VALUES - Compares the name fields based on ASCII values
- Writes the record with the lower name value to the merge file
- Continues until both files are exhausted
Code Example
PERFORM WITH TEST AFTER EOF-FLAG-1 AND EOF-FLAG-2
READ FILE-1
AT END SET EOF-FLAG-1 TO TRUE
MOVE HIGH-VALUES TO IN-NAME-1
END-READ
READ FILE-2
AT END SET EOF-FLAG-2 TO TRUE
MOVE HIGH-VALUES TO IN-NAME-2
END-READ
IF IN-NAME-1 IS < IN-NAME-2 THEN
WRITE RECORD-OUT FROM RECORD-1
ELSE
WRITE RECORD-OUT FROM RECORD-2
END-IF
END-PERFORM
Important Constraint
HIGH-VALUES and LOW-VALUES are alphanumeric in type, meaning numeric variables cannot directly receive these values without implicit redefinition.