DATA DIVISION for defining a class instance method
The DATA DIVISION
of an instance method
consists of any of the following four sections: FILE SECTION
, LOCAL-STORAGE
SECTION
, WORKING-STORAGE SECTION
, and LINKAGE
SECTION
.
About this task
-
FILE SECTION
- The same as a program
FILE SECTION
, except that a methodFILE SECTION
can defineEXTERNAL
files only. -
LOCAL-STORAGE SECTION
- A separate copy of the
LOCAL-STORAGE
data is allocated for each invocation of the method, and is freed on return from the method. The methodLOCAL-STORAGE SECTION
is similar to a programLOCAL-STORAGE SECTION
.If you specify the
VALUE
clause on a data item, the item is initialized to that value on each invocation of the method. -
WORKING-STORAGE SECTION
- A single copy of the
WORKING-STORAGE
data is allocated. The data persists in its last-used state until the run unit ends. The same copy of the data is used whenever the method is invoked, regardless of the invoking object or thread. The methodWORKING-STORAGE SECTION
is similar to a programWORKING-STORAGE SECTION
.If you specify the
VALUE
clause on a data item, the item is initialized to that value on the first invocation of the method. You can specify theEXTERNAL
clause for the data items. -
LINKAGE SECTION
- The same as a program
LINKAGE SECTION
.
If you define a data item with the same name in
both the DATA DIVISION
of an instance method and
the DATA DIVISION
of the OBJECT
paragraph,
a reference in the method to that data-name refers only to the method
data item. The method DATA DIVISION
takes precedence.