COBOL has various value types including alphanumeric (strings), numeric (integers and decimals), and boolean. Here are a few basic examples.
To run the program, compile the COBOL code and execute the resulting program:
In this COBOL example:
We define variables in the WORKING-STORAGE SECTION.
Strings are concatenated using the STRING verb.
Integer addition is performed using the ADD verb.
Decimal division is done with the DIVIDE verb.
Boolean operations are implemented using IF-ELSE statements.
Note that COBOL doesn’t have built-in boolean types, so we use ‘T’ for true and ‘F’ for false. Also, COBOL uses fixed-point decimal arithmetic, which is why the division result is more precise than floating-point arithmetic would be.