Object Data Type

The object data type allows you to define a Java™ object.

Start of changeIn a free-form definition, you specify the OBJECT keyword as the first keyword.
   DCL-S MyString OBJECT(*JAVA : 'java.lang.String');

   DCL-PR bdcreate OBJECT EXTPROC(*JAVA : 'java.math.BigDecimal'
                                : *CONSTRUCTOR);
      val UCS2(100) CONST;
   END-PR;
End of change
Start of changeIn a fixed-form definition, you specify the object data type as follows. In position 40, you specify data type O. In the keyword section, you specify the CLASS keyword to indicate the class of the object.
* Variable MyString is a Java String object.
D MyString        S               O   CLASS(*JAVA
D                                          :'java.lang.String')
D bdcreate        PR              O   EXTPROC(*JAVA
D                                            :'java.math.BigDecimal'
D                                            :*CONSTRUCTOR)
End of change

Start of changeFor both the OBJECT keyword and the CLASS keyword, you specify *JAVA for the first parameter, and the class name for the second parameter.End of change

Start of changeIf the object is the return type of a Java constructor, the class of the returned object is the same as the class of the method so you do not specify the parameters of the OBJECT keyword in a free-form definition, or the CLASS keyword in a fixed-form definition. Instead, you specify the EXTPROC keyword with environment *JAVA, the class name, and procedure name *CONSTRUCTOR.End of change

An object cannot be based. It also cannot be a subfield of a data structure.

If an object is an array or table, it must be loaded at runtime. Pre-run and compile-time arrays and tables of type Object are not allowed.

Every object is initialized to *NULL, which means that the object is not associated with an instance of its class.

To change the contents of an object, you must use method calls. You cannot directly access the storage used by the object.

Classes are resolved at runtime. The compiler does not check that a class exists or that it is compatible with other objects.