Initializing a table (INITIALIZE)
You can load a table by coding one or more INITIALIZE
statements.
About this task
For example, to move the value 3 into
each of the elementary numeric data items in a table called TABLE-ONE
,
shown below, you can code the following statement:
INITIALIZE TABLE-ONE REPLACING NUMERIC DATA BY 3.
To move the character 'X
'
into each of the elementary alphanumeric data items in TABLE-ONE
,
you can code the following statement:
INITIALIZE TABLE-ONE REPLACING ALPHANUMERIC DATA BY "X".
When you use the INITIALIZE
statement
to initialize a table, the table is processed as a group item (that
is, with group semantics); elementary data items within the group
are recognized and processed. For example, suppose that TABLE-ONE
is
an alphanumeric group that is defined like this:
01 TABLE-ONE.
02 Trans-out Occurs 20.
05 Trans-code Pic X Value "R".
05 Part-number Pic XX Value "13".
05 Trans-quan Pic 99 Value 10.
05 Price-fields.
10 Unit-price Pic 99V Value 50.
10 Discount Pic 99V Value 25.
10 Sales-Price Pic 999 Value 375.
. . .
Initialize TABLE-ONE Replacing Numeric Data By 3
Alphanumeric Data By "X"
The table below shows the content that
each of the twenty 12-byte elements Trans-out(n)
has
before execution and after execution of the INITIALIZE
statement
shown above:
Trans-out(n) before |
Trans-out(n) after |
---|---|
R13105025375 |
XXb030303003 1 |
|
You can similarly use an INITIALIZE
statement
to load a table that is defined as a national group. For example,
if TABLE-ONE
shown above specified the GROUP-USAGE
NATIONAL
clause, and Trans-code
and Part-number
had N
instead
of X
in their PICTURE
clauses, the
following statement would have the same effect as the INITIALIZE
statement
above, except that the data in TABLE-ONE
would instead
be encoded in UTF-16:
Initialize TABLE-ONE Replacing Numeric Data By 3
National Data By N"X"
The REPLACING NUMERIC
phrase
initializes floating-point data items also.
You can use the REPLACING
phrase of the INITIALIZE
statement
similarly to initialize all of the elementary ALPHABETIC
, DBCS
, ALPHANUMERIC-EDITED
, NATIONAL-EDITED
,
and NUMERIC-EDITED
data items in a table.
The INITIALIZE
statement
cannot assign values to a variable-length table (that is, a table
that was defined using the OCCURS DEPENDING ON
clause).
Examples: initializing data items
Initializing a structure (INITIALIZE)
Assigning values when you define a table (VALUE)
Assigning values to a variable-length table
Looping through a table
Using data items and group items
Using national groups