Initializing a structure (INITIALIZE)
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.
About this task
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 |
b000000000000000000000000000 1 |
2 | R001390000480000000000000000 |
b000000000000000000000000000 1 |
3 | S001410000120000000000000000 |
b000000000000000000000000000 1 |
4 | C001383000000000425000000000 |
b000000000000000000000000000 1 |
5 | C002010000000000000100000000 |
b000000000000000000000000000 1 |
|
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:
TRANSACTION-CODE
containsNX"2000"
(a national space).- Each of the remaining 27 national character positions of
TRANSACTION-OUT
containsNX"3000"
(a national-decimal zero).
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:
SPACE
is the implied sending item for alphabetic, alphanumeric, alphanumeric-edited, DBCS, category national, and national-edited receiving items.ZERO
is the implied sending item for numeric and numeric-edited receiving items.