Boolean value of numbers and strings in COBOL

Viewed 2386

Most programming languages recognize any non-zero number and non-blank string as true. I am wondering if COBOL does the same?

Example1: (9 && 2) is recognized (true && true) so returns true Example2: ("" && "Hello") is recognized (false && true) so returns false

Thanks!

2 Answers

Cobol does not have Boolean's as other languages do, it has 88 levels instead. 88 levels can be applied to other types. They cover boolean and enums in other languages.

Basic boolean 88 level

you can do

    05 Filler              pix x value 'N'.
       88 end-of-file value 'Y'.
       88 more-date-in-file value 'N'


    perform until   end-of-file
        ...

        read Transaction-File
         at end set end-of-file    to True
   end-perform

basic enum 88 level

  03 Transaction-Code                pic s9(4) comp-3.
     88 Purchase-Transaction value    1000, 1001, 1005 thru 1009.
     88 Sales-Transaction    value    2000, 2010, 2020.
     88 Price-Adjustment     value    2050.
     88 Transfer-Transaction value    1050.



  evaluate true
     when Purchase-Transaction
       ...
     when Sales-Transaction    
       ...

Summary

88 levels provide basic boolean variables (but no boolean algebra). They also allow you to document the possible values a variable can take + there meaning.

88 levels are one of the nicer features of Cobol especially when used with files. It allows you to define exactly what values a Field in a File can have. In Java etc, you could define constants but you can not link a Constant to a variables. You can use enum's but that will require extra code and are limited to one value. Of course files are not as important as they once where.

From a Google search:

Boolean data items COBOL does not directly support logical/boolean variables; however, level-88 is used to define condition names which have the same effect.

Related