Problem using INITIALIZE TO VALUE with VALUE clause on group item
There is a problem when trying to use the INITIALIZE statement with the TO VALUE phrase on a group item whose VALUE clause is specified at the group level instead of at the elementary level.
It seems to be ignored by the compiler:
01 TEST-INIT1 VALUE HIGH-VALUES.
03 TEST-FIELD1 PIC X.
03 TEST-FIELD2 PIC X.
03 TEST-FIELD1 PIC X VALUE HIGH-VALUES.
03 TEST-FIELD2 PIC X VALUE HIGH-VALUES.
INITIALIZE TEST-INIT1 ALL TO VALUE
INITIALIZE TEST-INIT2 ALL TO VALUE
In above example, it seems like INITIALIZE TEST-INIT1 ALL TO VALUE is being ignored and in fact when stepping thru code the line is jumped over.
This results in its elementary items being initialized to X”20”.
The same is not true for INITIALIZE TEST-INIT2 ALL TO VALUE as it results in its elementary items being initialized to X”FF”.
Why is this?
There are actually several General Rules outlined in the ISO-2002 COBOL standard that exclude group items from being receiving items when the TO VALUE phrase is used on the INITIALIZE statement.
The following rule also specifies that the VALUE clause must be specified in the description of the elementary item.
c. Finally, each possible receiving operand is a receiving operand if at least one of the following is true:
i. The VALUE phrase is specified, the category of the elementary data item is one of the categories specified or implied in the VALUE phrase, and one of the following is true:
A. Either the category of the elementary data item is data-pointer, object-reference, or program-pointer.
B. A data-item format or table format VALUE clause is specified in the data description entry of the elementary data item.