|
4.3 Initializing Data
During a program run it is often necessary to reset an item, or group of items, back to zero (or other value), or
back to a certain literal. Often the program requires data to be set at a certain value (or set literal) at the beginning
of a run. For example, an item may be used to count the number of records that have been read by the program. each time this has occurred
the line:
COMPUTE REC-COUNT = REC-COUNT + 1
Obviously, the first time REC-COUNT is encountered, it would need to have a value (probably zero). This could be acheived
in the data division:
01 REC-COUNT PIC 9(4) VALUE ZERO.
Alternatively, early in the procedure division, the command
MOVE ZERO TO REC-COUNT
would have the same effect. If, however, you wished to set a group of items to zero (to zeroize) and/or set other
alphanumeric items in that group to spaces then you could use the INITIALIZE verb. For example:
000200 DATA DIVISION.
000210 WORKING-STORAGE SECTION
000220 01 DATA-GROUP.
000230 03 REC-COUNTER PIC 9(4).
000240 03 REC-TYPE PIC X(2).
000250 03 REC-DATE PIC 9(6).
000260 03 FILLER PIC X(14) VALUE 'Record details'.
And in the procedure division:
000400 INITIALIZE DATA-GROUP
The effect of this will be that whatever the contents of any of the level 03 items prior to the initialize statement
REC-COUNTER will now contain zero, as will REC-DATE, and REC-TYPE will contain spaces. However, FILLER (the last item), is actually
a reserved word and refers to an used area. The word 'FILLER' can actually be omitted (i.e. 01        PIC X(14)
VALUE 'Record details'.).
As you will see in the Printing/writing data part of the next section, a literal can be assigned to this. Following
initialization the filler will remain unchanged (and not space-filled).
|