Examples: initializing data items

The following examples show how you can initialize many kinds of data items, including alphanumeric, national-edited, and numeric-edited data items, by using INITIALIZE statements.

An INITIALIZE statement is functionally equivalent to one or more MOVE statements. The related tasks about initializing show how you can use an INITIALIZE statement on a group item to conveniently initialize all the subordinate data items that are in a given data category.

Initializing a data item to blanks or zeros:


INITIALIZE identifier-1

identifier-1 PICTURE identifier-1 before identifier-1 after
9(5) 12345 00000
X(5) AB123 bbbbb1
N(3) 0041004200312 0020002000203
99XX9 12AB3 bbbbb1
XXBX/XX ABbC/DE bbbb/bb1
**99.9CR 1234.5CR **00.0bb1
A(5) ABCDE bbbbb1
+99.99E+99 +12.34E+02 +00.00E+00
  1. The symbol b represents a blank space.
  2. Hexadecimal representation of the national (UTF-16) characters 'AB1'. The example assumes that identifier-1 has Usage National.
  3. Hexadecimal representation of the national (UTF-16) characters '   ' (three blank spaces). Note that if identifier-1 were not defined as Usage National, and if NSYMBOL(DBCS) were in effect, INITIALIZE would instead store DBCS spaces ('4040') into identifier-1.

Initializing an alphanumeric data item:


01  ALPHANUMERIC-1    PIC X    VALUE "y".
01  ALPHANUMERIC-3    PIC X(1) VALUE "A".
. . .
    INITIALIZE ALPHANUMERIC-1
        REPLACING ALPHANUMERIC DATA BY ALPHANUMERIC-3

ALPHANUMERIC-3 ALPHANUMERIC-1 before ALPHANUMERIC-1 after
A y A

Initializing an alphanumeric right-justified data item:


01  ANJUST            PIC X(8)  VALUE SPACES  JUSTIFIED RIGHT.
01  ALPHABETIC-1      PIC A(4)  VALUE "ABCD".
. . .
    INITIALIZE ANJUST
        REPLACING ALPHANUMERIC DATA BY ALPHABETIC-1

ALPHABETIC-1 ANJUST before ANJUST after
ABCD bbbbbbbb1 bbbbABCD1
  1. The symbol b represents a blank space.

Initializing an alphanumeric-edited data item:


01  ALPHANUM-EDIT-1   PIC XXBX/XXX  VALUE "ABbC/DEF".
01  ALPHANUM-EDIT-3   PIC X/BB      VALUE "M/bb".
. . .
    INITIALIZE ALPHANUM-EDIT-1
        REPLACING ALPHANUMERIC-EDITED DATA BY ALPHANUM-EDIT-3

ALPHANUM-EDIT-3 ALPHANUM-EDIT-1 before ALPHANUM-EDIT-1 after
M/bb1 ABbC/DEF1 M/bb/bbb1
  1. The symbol b represents a blank space.

Initializing a national data item:


01  NATIONAL-1        PIC NN  USAGE NATIONAL  VALUE N"AB".
01  NATIONAL-3        PIC NN  USAGE NATIONAL  VALUE N"CD".
. . .
    INITIALIZE NATIONAL-1
        REPLACING NATIONAL DATA BY NATIONAL-3
    INITIALIZE NATIONAL-1 NATIONAL TO VALUE

NATIONAL-3 NATIONAL-1 before first INITIALIZE NATIONAL-1 after first INITIALIZE NATIONAL-1 after second INITIALIZE
004300441 004100422 004300441 004100422
  1. Hexadecimal representation of the national characters 'CD'
  2. Hexadecimal representation of the national characters 'AB'

Initializing a national-edited data item:


01  NATL-EDIT-1       PIC 0NN  USAGE NATIONAL  VALUE N"123".
01  NATL-3            PIC NNN  USAGE NATIONAL  VALUE N"456".
. . .
    INITIALIZE NATL-EDIT-1
        REPLACING NATIONAL-EDITED DATA BY NATL-3

NATL-3 NATL-EDIT-1 before NATL-EDIT-1 after
0034003500361 0031003200332 0030003400353
  1. Hexadecimal representation of the national characters '456'
  2. Hexadecimal representation of the national characters '123'
  3. Hexadecimal representation of the national characters '045'

Initializing a numeric (zoned decimal) data item:


01  NUMERIC-1         PIC 9(8)        VALUE 98765432.
01  NUM-INT-CMPT-3    PIC 9(7)  COMP  VALUE 1234567.
. . .
    INITIALIZE NUMERIC-1
        REPLACING NUMERIC DATA BY NUM-INT-CMPT-3

NUM-INT-CMPT-3 NUMERIC-1 before NUMERIC-1 after
1234567 98765432 01234567

Initializing a numeric (national decimal) data item:


01  NAT-DEC-1         PIC 9(3)  USAGE  NATIONAL VALUE 987.
01  NUM-INT-BIN-3     PIC 9(2)  BINARY VALUE 12.
. . .
    INITIALIZE NAT-DEC-1
        REPLACING NUMERIC DATA BY NUM-INT-BIN-3

NUM-INT-BIN-3 NAT-DEC-1 before NAT-DEC-1 after
12 0039003800371 0030003100322
  1. Hexadecimal representation of the national characters '987'
  2. Hexadecimal representation of the national characters '012'

Initializing a numeric-edited (USAGE DISPLAY) data item:


01  NUM-EDIT-DISP-1   PIC $ZZ9V  VALUE "$127".
01  NUM-DISP-3        PIC 999V   VALUE 12.
. . .
    INITIALIZE NUM-EDIT-DISP-1
        REPLACING NUMERIC-EDITED DATA BY NUM-DISP-3

NUM-DISP-3 NUM-EDIT-DISP-1 before NUM-EDIT-DISP-1 after
012 $127 $ 12

Initializing a numeric-edited (USAGE NATIONAL) data item:


01  NUM-EDIT-NATL-1   PIC $ZZ9V  NATIONAL VALUE N"$127".
01  NUM-NATL-3        PIC 999V   NATIONAL VALUE 12.
. . .
    INITIALIZE NUM-EDIT-NATL-1
        REPLACING NUMERIC-EDITED DATA BY NUM-NATL-3

NUM-NATL-3 NUM-EDIT-NATL-1 before NUM-EDIT-NATL-1 after
0030003100321 00240031003200372 00240020003100323
  1. Hexadecimal representation of the national characters '012'
  2. Hexadecimal representation of the national characters '$127'
  3. Hexadecimal representation of the national characters '$ 12'