How to represent the Boolean "true" and "false" in COBOL

1 Answer

0 votes
*> In COBOL, Boolean values are not built‑in the way they are in modern languages.
*> Instead, COBOL uses condition names (also called 88‑level items) 
*> to represent logical true/false states.

*> You define a data item, then attach 88‑level condition names to it:
*> When the variable has a specific value -> the condition name is TRUE
*> Otherwise -> it is FALSE

IDENTIFICATION DIVISION.
PROGRAM-ID. BooleanExample.

DATA DIVISION.
WORKING-STORAGE SECTION.

*> A numeric variable that will hold a state
01  SWITCH-FLAG        PIC 9 VALUE 1.

    *> 88-level condition names (Boolean-like)
    88  FLAG-TRUE      VALUE 1.
    88  FLAG-FALSE     VALUE 0.

PROCEDURE DIVISION.
    DISPLAY "Initial state:"
    IF FLAG-TRUE
        DISPLAY "FLAG is TRUE"
    ELSE
        DISPLAY "FLAG is FALSE"
    END-IF

    *> Change the flag
    MOVE 0 TO SWITCH-FLAG

    DISPLAY "After change:"
    IF FLAG-FALSE
        DISPLAY "FLAG is FALSE"
    ELSE
        DISPLAY "FLAG is TRUE"
    END-IF

    STOP RUN.
    
    
*> run:
*>
*> Initial state:
*> FLAG is TRUE
*> After change:
*> FLAG is FALSE
*>

 



answered 6 days ago by avibootz
...