Mapping Dataset Model properties to Enums

Enums are a great way for a programmer to define a range of possible values for a property or a parameter to a method. They simplify the interface and help greatly to avoid errors and reduce testing.

We have recently implemented the ability to map Integer or Character fields in a Business Entities Dataset to Enum properties in the Dataset Model that can be used to access this Business Entity. When using the Dataset Model to access data from a Business Entity this would allow to map field values such as "Shipped" or "Ordered" to an Enum member such as "Demo.OrderStatusEnum:Shipped" and "Demo.OrderStatusEnum:Ordered".

We currently do not plan to add an (automatic) mapping between Character and Integer fields within the Business Entity itself. The Dataset could only contain Progress.Lang.Object fields to reference to Enum values which misses the whole point of strong typing completely (we could not avoid on the Interface level that the WeekDayEnum would be used to assign an value to the OrderStatus field of the Order Table). Further while (ABL or Consultingwerk) Enums are great within the ABL application, they may be problematic outside of the AppServer application when the Business Entity is used by REST, .NET or Java Clients.

Functional Limitation

We currently cannot map character values such as "Invoice Pending" to an Enum member. This is simply because the ABL does not support Enum members with a space character in the name.

Mapping Dataset fields to Enum

In the Business Entity Designer, use the Custom Field Properties Dialog to select the existing Enum type that the Character or Integer property should be mapped to.

Then add a new custom properties entry, the Property Name combo box will allow you to use "ModelClassGenerator.CustomPropertyType" as the property name and the Property Value combo box will be populated with all Enums found in your work space (using the Consultingwerk.Util.ClassHelper). The process does support Consultingwerk Enum's (on any supported Progress release) and ABL native Enums on OpenEdge 11.6.

After generating the Dataset Model for the Business Entity the OrderStatus property will be generated with the OrderStatusEnum type and the underlying Character value will be hidden.

Referencing the Enums in Application Code

Read Access to Enum properties:

IF oOrder:Order:OrderStatus = OrderStatusEnum:Ordered THEN DO:
    
END .      

Set Access to Enum properties:

oOrder:Order:OrderStatus = OrderStatusEnum:Ordered .