Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


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) 4100420031002 2000200020003
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' in UTF-16LE encoding. The example assumes that identifier-1 has Usage National.
  3. Hexadecimal representation of the national (UTF-16) characters '   ' (three blank spaces) in UTF-16LE encoding. Note that if identifier-1 were not defined as Usage National, and if NSYMBOL(DBCS) were in effect, INITIALIZE would instead store DBCS spaces ('2020') 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

NATIONAL-3 NATIONAL-1 before NATIONAL-1 after
430044001 410042002 430044001
  1. Hexadecimal representation of the national characters 'CD' in UTF-16LE encoding
  2. Hexadecimal representation of the national characters 'AB' in UTF-16LE encoding

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
3400350036001 3100320033002 3000340035003
  1. Hexadecimal representation of the national characters '456' in UTF-16LE encoding
  2. Hexadecimal representation of the national characters '123' in UTF-16LE encoding
  3. Hexadecimal representation of the national characters '045' in UTF-16LE encoding

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 3900380037001 3000310032002
  1. Hexadecimal representation of the national characters '987' in UTF-16LE encoding
  2. Hexadecimal representation of the national characters '012' in UTF-16LE encoding

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 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 DATA BY NUM-NATL-3

NUM-NATL-3 NUM-EDIT-NATL-1 before NUM-EDIT-NATL-1 after
3000310032001 24003100320037002 24002000310032003
  1. Hexadecimal representation of the national characters '012' in UTF-16LE encoding
  2. Hexadecimal representation of the national characters '$127' in UTF-16LE encoding
  3. Hexadecimal representation of the national characters '$ 12' in UTF-16LE encoding

related tasks
Initializing a structure (INITIALIZE)
Initializing a table (INITIALIZE)
Defining numeric data

related references
NSYMBOL


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)