You can reset the values of all subordinate data items in a group item by applying the INITIALIZE statement to that group item. However, it is inefficient to initialize an entire group unless you really need all the items in the group to be initialized.
The following example shows how you can reset fields to spaces and zeros in transaction records that a program produces. The values of the fields are not identical in each record that is produced. (The transaction record is defined as an alphanumeric group item, TRANSACTION-OUT.)
01 TRANSACTION-OUT.
05 TRANSACTION-CODE PIC X.
05 PART-NUMBER PIC 9(6).
05 TRANSACTION-QUANTITY PIC 9(5).
05 PRICE-FIELDS.
10 UNIT-PRICE PIC 9(5)V9(2).
10 DISCOUNT PIC V9(2).
10 SALES-PRICE PIC 9(5)V9(2).
. . .
INITIALIZE TRANSACTION-OUT
| Record | TRANSACTION-OUT before | TRANSACTION-OUT after |
|---|---|---|
| 1 | R001383000240000000000000000 | b0000000000000000000000000001 |
| 2 | R001390000480000000000000000 | b0000000000000000000000000001 |
| 3 | S001410000120000000000000000 | b0000000000000000000000000001 |
| 4 | C001383000000000425000000000 | b0000000000000000000000000001 |
| 5 | C002010000000000000100000000 | b0000000000000000000000000001 |
|
||
You can likewise reset the values of all the subordinate data items in a national group item by applying the INITIALIZE statement to that group item. The following structure is similar to the preceding structure, but instead uses Unicode UTF-16 data:
01 TRANSACTION-OUT GROUP-USAGE NATIONAL.
05 TRANSACTION-CODE PIC N.
05 PART-NUMBER PIC 9(6).
05 TRANSACTION-QUANTITY PIC 9(5).
05 PRICE-FIELDS.
10 UNIT-PRICE PIC 9(5)V9(2).
10 DISCOUNT PIC V9(2).
10 SALES-PRICE PIC 9(5)V9(2).
. . .
INITIALIZE TRANSACTION-OUT
Regardless of the previous contents of the transaction record, after the INITIALIZE statement above is executed:
When you use an INITIALIZE statement to initialize an alphanumeric or national group data item, the data item is processed as a group item, that is, with group semantics. The elementary data items within the group are recognized and processed, as shown in the examples above. If you do not code the REPLACING phrase of the INITIALIZE statement:
related concepts
National groups
related tasks
Initializing a table (INITIALIZE)
Using national groups
related references
INITIALIZE statement
(COBOL for Windows Language Reference)