In the following example, when storage is allocated for Name, the character constant 'John Doe' (padded on the right to 10 characters) is assigned to it.
dcl Name char(10) init('John Doe');
In the following example, when Pi is allocated, it is initialized to the value 3.1416.
dcl Pi fixed dec(5,4) init(3.1416);
The following example specifies that A is to be initialized with the value of the expression B*C:
declare A init((B*C));
The following example results in each of the first 920 elements of A being set to 0. The next 80 elements consist of 20 repetitions of the sequence 5,5,5,9.
declare A (100,10) initial
((920)0, (20) ((3)5,9));
In the following example, only the first, third, and fourth elements of A are initialized; the rest of the array is not initialized. The array B is fully initialized, with the first 25 elements initialized to 0, the next 25 to 1, and the remaining elements to 0. In the structure C, where the dimension (8) has been inherited by D and E, only the first element of D is initialized. All the elements of E are initialized.
declare A(15) character(13) initial
('John Doe',
*,
'Richard Row',
'Mary Smith'),
B (10,10) decimal fixed(5)
init((25)0,(25)1,(*)0),
1 C(8),
2 D initial (0),
2 E initial((*)0);
When an array of structures or unions is declared with the LIKE attribute to obtain the same structuring as a structure or union whose elements have been initialized, only the first structure or union is initialized.
In the following example only J(1).H and J(1).I are initialized in the array of structures.
declare 1 G,
2 H initial(0),
2 I initial(0),
1 J(8) like G;