Created On:  06 December 2011

Problem:

We have a data structure defined as follows:

      01  TEST-INIT1   VALUE     HIGH-VALUES.
            05  TEST-FIELD1    PIC X.
            05  TEST-FIELD2    PIC X.

In the procedure division we initialize this structure using:

           INITIALIZE TEST-INIT1  ALL TO VALUE THEN TO DEFAULT

The elementary fields are correctly initialized to HIGH-VALUES at startup (tested in both WORKING and LOCAL-STORAGE) but INITIALIZE reverts the structures back to spaces.

How can we re-initialize these structures?

Resolution:

The problem you are seeing is because the THEN TO DEFAULT phrase is overriding the TO VALUE phrase when the value statement is specified at group level.

       01  TEST-INIT1   VALUE     HIGH-VALUES.
             05  TEST-FIELD1    PIC X.
             05  TEST-FIELD2    PIC X.

       01  TEST-INIT2.
             05  TEST-FIELD1    PIC X VALUE HIGH-VALUES.
             05  TEST-FIELD2    PIC X VALUE HIGH-VALUES.

       PROCEDURE DIVISION.
    
           INITIALIZE TEST-INIT1  ALL TO VALUE THEN TO DEFAULT
           INITIALIZE TEST-INIT2  ALL TO VALUE THEN TO DEFAULT

In the above two structures the initialize statements are not treated the same.

In TEST-INIT1 the value clause is at the group level and the elementary items under it do not have a value clause.

So when you execute:

           INITIALIZE TEST-INIT1  ALL TO VALUE THEN TO DEFAULT

The group item is first initialized to high-values (because it has a value clause) resulting in high-values in each of the elementary items under it .

Then the THEN TO DEFAULT phrase is executed for all items without a value clause (the elementary items) and the elementary items are then set to spaces.

In TEST-INIT2 each of the elementary items has a value clause so they are set to high-values for the VALUE phrase and are not affected by the THEN TO DEFAULT phrase because they do have values specified.

If you remove the THEN TO DEFAULT phrase from the INITIALIZE statement for the first group then the elementary items will be initialized to high-values.

Incident #2549653