TypeCobolTypes - TypeCobolTeam/TypeCobol GitHub Wiki
A TYPE
is both a structure of data and definition of a type.
TypeCobol syntax |
Translation into Cobol 85 |
You can declare a TYPE 01 Person TYPEDEF STRICT.
05 Id pic 9(05).
05 lastName pic X(30).
05 FirstName pic X(30).
05 BirthDate pic X(08). |
|
You can then use 01 person1 TYPE Person. |
Which is equivalent to: 01 person1.
02 Id pic 9(05).
02 lastName pic X(30).
02 FirstName pic X(30).
02 BirthDate pic X(08). |
A 01 person1 TYPE Person.
01 MyData.
05 Array occurs 5.
10 person2 TYPE Person. |
Which is equivalent to: 01 person1.
02 Id pic 9(05).
02 lastName pic X(30).
02 FirstName pic X(30).
02 BirthDate pic X(08).
01 MyData.
05 Array occurs 5.
10 person2.
11 Id pic 9(05).
11 lastName pic X(30).
11 FirstName pic X(30).
11 BirthDate pic X(08). |
A TYPE
allow you to control assignment to a variable.
Only variable of the same TYPE
can be moved into each other.
With the following declaration:
01 Person TYPEDEF STRICT.
05 Id pic 9(05).
05 lastName pic X(30).
05 FirstName pic X(30).
05 BirthDate pic X(08).
01 person1 TYPE Person.
01 person2 TYPE Person.
01 person3 pic X(30).
person2
is of TYPE Person
and can only be assigned from Person1
.
move person1 to person2 *> OK
move person3 to person2 *> KO - type not equals
-
Weak (like Cobol 2002 ISO Specifications)
-
The type is only used as a structure
-
-
Strict (TypeCobol)
-
Strict represent both a structure and a type
-
-
Strong (like Cobol 2002 ISO Specifications)
-
Strong represent both a structure and a type.
-
It’s an equivalent of Strict, but you cannot have a
value
clause or a picture directly on the Typedef data element.
-
To reference a Type from another program, you must first declare it PUBLIC
:
ID DIVISION.
PROGRAM-ID. PgmA.
data division.
working-storage section.
01 Person TYPEDEF STRICT PUBLIC.
05 Id pic 9(05).
05 lastName pic X(30).
05 FirstName pic X(30).
05 BirthDate pic X(08).
END PROGRAM PgmA.
You can then prefix the type with the program name:
ID DIVISION.
PROGRAM-ID. PgmB.
data division.
working-storage section.
01 MyPerson TYPE PgmA::Person.
END PROGRAM PgmB.
Use operator ::
instead of operator of
or in
.
-
typed pointer