NETJVM 

Enumerations and Enum types

An enumeration represents a list of constant values, such as values for the days of the week. You can declare an enum type that defines the values and symbolic names for them. You can then refer to the values by name.

For example, you could declare an enum type for the days of the week, as follows:

enum-id DaysOfWeek as "DaysOfWeek".
       01 binary-long. 
          78 Sunday value 0. *> optional, as 0 is the default 
          78 Monday.         *> by default, this is value 1
          78 Tuesday.        *> by default, this is value 2 and so on
          78 Wednesday.      
          78 Thursday.       
          78 Friday. 
          78 Saturday. 
       end enum.

You can then refer to the enum type in your code, as follows:

set today to type DaysOfWeek::Monday

Where DaysOfWeek::Monday represents the binary-long value 1.

The Compiler adds a static method called 'values' that returns an array containing the values of the enum. You can use this method together with the PERFORM THROUGH construct to iterate over the values of an enum type.

You declare an enum using the ENUM-ID paragraph. This is followed by a working-storage section consisting of:

Note: In COBOL for JVM, as in Java, the enum declaration defines an enum class, which is a class that derives from java.lang.Enum. In Java, this enum class can include methods and other fields explicitly declared by the user, whereas this is not allowed in COBOL.