Type Specifier

A type specifier is a declaration of a type, such as a class, interface, enum and so on.

type-specifier

Syntax of the simple type specifier 
 simple-type-specifier

simple-type-specifier

 
 predefined-type-specifier

predefined-type-specifier

Example

Predefined Types
  01 dAmount  decimal.
  01 asNames string occurs 5.
  01 abFigures binary-long occurs any.
TYPE keyword
  01 objMyType type MyType.  
  01 objDateTime type DateTime.        *> .NET COBOL
  01 objDateTime type java.util.Date.  *> JVM COBOL

Where:

  • objMyType is defined as an object of type MyType
  • objDateTime is defined as an object type DateTime in .NET COBOL or java.util.Date in JVM COBOL.

Long Type Names

To define a namespace to represent long class names so that you need to type a short name only, use the ILUSING directive.

Type Compatibility with .NET Types

All the predefined COBOL data types and any further .NET COBOL types that you define are mapped onto the corresponding native managed type (.NET or JVM), but they must conform to the following rules. They:

  • Must be declared at 01 (or 77) level
  • Must have no REDEFINES or RENAMES
  • Must never be the subject of reference modification
  • Must never be the subject of the ADDRESS OF clause
  • May use format 3 of the OCCURS clause to declare an array

Any COBOL data item that does not follow these rules, or is of any other category, is not considered to be a managed type (.NET or JVM) and is allocated by the Compiler within an internally managed byte array. COBOL pointer data items always point into one of these byte arrays.

Generic Types

In .NET COBOL, to refer to a generic type using the TYPE literal syntax, you enumerate the generic parameters within square brackets. The following example declares myNames as an item of type Dictionary (for .NET COBOL) or HashMap (for JVM COBOL), with both generic parameters set to string - System.String for .NET COBOL, and java.lang.String for JVM COBOL:

myNames type System.Collections.Generic.Dictionary[string, string]. *> .NET COBOL
myNames type java.util.HashMap[string, string]. *> JVM COBOL	 

Nullable Types

The keyword NULLABLE is used to define nullable types. It can only be used with value types.