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.
A D V E R T I S E M E N T
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:
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).