Context:
Classes ValueTypes Interfaces Type Members
|
class-id MyClass. working-storage section. 01 volume binary-long private. property-id Volume binary-long. getter. set property-value to volume setter. if property-value < 0 set volume to 0 else set volume to property-value end-if end property. 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 Enterprise Developer > Samples > Visual COBOL Samples, under Language Reference for JVM COBOL.
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.