ENUM statement

Defines a user-defined enumeration (also known as an enumerated type or enum). An enum is made up of a list of strongly typed, named constants called members. The value of a variable defined as an enum is restricted to the list of members defined for that enum. Some of the advantages of enums are that they are self-documenting, strongly typed, and validated at compile time (i.e., the compiler verifies that a variable defined as an enum can only contain values defined by that enum).

In addition to being named, each member also has an underlying numeric value associated with it. By default, the compiler sets those associated values automatically. Generally, you do not need to worry about the numerical values, but you can specify one or more of the values explicitly if desired.

You can define two types of enum. In the standard version, a variable defined as an enum can only be assigned one value at a time. You can also define a flag enum. Any variable defined as a flag enum can be assigned any combination of the members (also referred to as "flags" for flag enums) at one time. You can perform operations on flag enum variables to set and unset one or more of the flags.

All enums implicitly inherit from one of two classes. The single-value enums inherit from Progress.Lang.Enum, and flag enums inherit from Progress.Lang.FlagsEnum, which is a subclass of Progress.Lang.Enum. See the Progress.Lang.Enum class and Progress.Lang.FlagsEnum class entries for more information.

Syntax

ENUM enum-type-name [FLAGS]:
    DEFINE ENUM enum-member-definition
              [enum-member-definition] ...
END [ENUM].    
enum-type-name
Defines the type name for a user-defined enum. You can specify an ABL enum name in a way similar to how you specify an ABL class type. All the requirements and restrictions on how to specify an ABL class type apply to an enum. See the CLASS statement and Type-name syntax entries for more details.
FLAGS
Defines the enum as a flag enum, with the defined members acting as flags. This allows you to set one or more flags into the same variable. You can define up to 64 distinct members to be used as flags. You can also define a flag as a combination of other flags, and a flag defined this way does not count as a distinct flag.
enum-member-definition
Defines a member using the following syntax:
member-name [ = {member-name [, member-name]... }
    | constant ]     
member-name
Specifies the name of the member. Each member name must be unique among the names of all members defined in the enum as well as all properties, events, and variable data members that are defined in the class hierarchy and accessible to the defining class. The rules for member names follow the same rules that are in place for variable and property names. Member names are case insensitive and can be reserved keywords.
member-name [, member-name]
Assigns the same numeric value as a previously defined member. In this way, you can define multiple members as equivalent with the same underlying value. For flag enums, you can also equate an member with multiple, previously defined members, entered as a comma-delimited list. See the Examples section for more information.
constant
Defines the numeric value associated with the member. The value must be a constant of type INT64. The value can be represented in hexadecimal notation (for easier readability with flag enums, for example).
If the first member is not explicitly assigned a value, the compiler starts with a value of 1. For each subsequent member not assigned a value, the compiler assigns a value 1 larger than the previous member for a single-value enum, or the next power of 2 for a flag enum.
Note: Flag enums are the primary use case for explicitly setting the underlying values of members. Progress recommends that, when defining a flag enum, you always explicitly define a member with a value of 0.
END [ENUM]
Specifies the end of the enum definition. You must end the enum definition with the END statement.

Examples

The following example shows how to define an enum with the four cardinal directions as its named values:

ENUM Direction:
    DEFINE ENUM North
                South
                East
                West.
END ENUM.			

The next example shows how to define an member as equivalent to another:

ENUM Direction:
    DEFINE ENUM North
                Default = North
                South
                East
                West.
END ENUM.			

In this case, both North and Default have an underlying value of 1.

The following is an example of a flag enum, including the member ReadWrite being defined as a combination of previously defined members:

ENUM Permission FLAGS:
    DEFINE ENUM None = 0
                Read
                Write
                Update = Write
                ReadWrite = Read,Write
                Create
                Delete
                Execute.
END ENUM.

For flag enums, it is recommended that you include an member with an underlying value of 0, representing no flags set. Because the compiler automatically starts with a value of 1 for both single-value and flag enums, you must define an member with a value of 0 explicitly.

The syntax for assigning a value to a variable defined as an enum is similar to the syntax used to assign values to static data members of a class:

enum-type-name:member-name    

Using the Direction enum from the first example, this code fragment defines myDirection as a variable of type Direction and assigns myDirection the member South:

DEFINE VARIABLE myDirection AS Direction.

myDirection = Direction:South.			

This syntax cannot be used to set multiple flags for a variable defined as a flag enum. To set multiple flags, you need to use bitwise operators or the SetFlag( ), ToggleFlag( ), and UnsetFlag( ) methods, as described in the Notes section of this entry.

Members are read-only, so the following code will not compile:

Direction:South = myDirection.			

Like other uninitialized class references, variables defined as enums have an initial value of the unknown (?) value.

Notes

See also

AND operator (bitwise), Assignment (=) statement, Class-based object reference, DYNAMIC-ENUM function, NOT operator (bitwise), , OR operator (bitwise), Progress.Lang.Enum class, Progress.Lang.FlagsEnum class, Type-name syntax, USING statement, XOR operator (bitwise)