値タイプ

値タイプには、クラスと同様にデータ・メンバと関数メンバを含めることができます。違いは、値タイプはデータを値として保存し、ヒープ割り当てを必要としない点です。

コンテキスト:

    プログラムの構造
        タイプ

valuetype-specification

valuetype-header constraints-paragraph static-or-instance-field static-or-instance-member

valuetype-header

access-modifier type-specifier attribute-clause

valuetype-id StudentRecord.
01 aName string public.
01 gpa float-short public.
method-id new.
procedure division using by value nam as string, 
                                  gpa as float-short.
    set aName to nam
    set self::"gpa" to gpa
end method.
end valuetype.
 
class-id a.
method-id main static.
local-storage section.
01 stu type StudentRecord value new StudentRecord("Bob", 3.5).
01 stu2 type StudentRecord.
procedure division.
    set stu2 to stu
    set stu2::name to "Sue"
    display stu::name   *> Bob を印刷する
    display stu2::name  *> Sue を印刷する
end method.
end class.