class-id Things. 01 _size binary-long private. 01 ReadOnly binary-long property with no set value 3. 01 ReadWrite binary-long property. property-id Size binary-long. *> Use property-value inside properties to *> pass the value in or out getter. set property-value to _size setter. if property-value < 0 set _size to 0 else set _size to property-value end-if end property. method-id main static. declare foo = new Things() add 1 to foo::Size display foo::Size display foo::ReadOnly set foo::ReadWrite to 22 end method. end class.
property-id PropertyReadOnly string. getter. set property-value to field-5 end property.
See also the Properties sample, available from Start > All Programs > Micro Focus Visual COBOL > Samples, under COBOL for .NET .
A property specified using PROPERTY-ID must contain a get or set accessor (or both), using the GETTER and SETTER keywords respectively. The Compiler then generates get_ and set_ methods accordingly.
There are two ways of exposing a field as a property within a COBOL program:
The FOR Clause
Use the FOR clause as an explicit interface implementation, which is particularly useful when the containing class implements two different interfaces, and these two interfaces have PROPERTY-IDs with the same name and type. In this case, by using the FOR phrase, you can supply two different implementations of the PROPERTY-IDs for the two different interfaces.
property-id PropertyReadOnly string FOR MyInterface1. getter. set property-value to field-1 end property. property-id PropertyReadOnly string FOR MyInterface2. getter. set property-value to field-2 end property.