Context:
Program Structure Types
|
enum-id Action. 78 #Start. *> Start is a reserved word so use '#' symbol 78 #Stop. 78 #Rewind. 78 #Forward. end enum. enum-id Status. 78 Flunk value 50. 78 Pass value 70. 78 Excel value 90. end enum. class-id MainClass. method-id main static. declare a = type Action::Stop if a not = type Action::Start display a & " is " & a as binary-long *> Prints "Stop is 1" end-if display type Status::Pass as binary-long *> prints 70 display type Status::Pass *> prints end method. end class.
See also the Enums sample, available from Start > All Programs > Micro Focus Enterprise Developer > Samples > Visual COBOL Samples, under COBOL for .NET.
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.
The enum-header is followed by a working-storage section consisting of:
In COBOL for .NET, but not JVM, you can set the attribute System.FlagsAttribute. This attribute applied to an enum means that the distinct values are to be regarded as bit settings, and can therefore be combined. For example:
enum-id MyFlags attribute System.FlagsAttribute.
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.