Page 1 of 1

Is there a way to force fully qualified variables

PostPosted: Fri Nov 04, 2016 5:57 pm
by kenW
Hi have a test case where a group appears in a record more than once. They are at different levels but under the same higher level group.

01 AAA.
   02  BBB.
       07  DDD.
           12  EEE PIC X(1).
       07  CCC.
           12  DDD.
               17  EEE PIC X(1).
 

I cannot reference the first EEE because "EEE OF DDD OF BBB OF AAA" is not unique since the compiler can use that qualification as either EEE.

If I have code like "MOVE 'Z' TO EEE OF DDD OF BBB OF AAA." I get error - IGYPS0037-S "EEE OF DDD OF BBB OF AAA" was not a uniquely defined name.

Is there a way (compiler option?) to force the compiler to use fully qualified names only?

Re: Is there a way to force fully qualified variables

PostPosted: Fri Nov 04, 2016 6:35 pm
by Robert Sample
As you have your code now, you CANNOT directly reference your first EEE variable. This is not a COBOL issue, hence there is no way to force COBOL to allow you to reference it as coded. You have three choices:
1. Forget referencing the first EEE variable directly.
2. Add another unique variable name between AAA and the first EEE that allows you to uniquely reference that variable.
3. Change the name of the first EEE variable to something else.

Re: Is there a way to force fully qualified variables

PostPosted: Fri Nov 04, 2016 7:19 pm
by kenW
Thanks Roberts. These options make sense. I'm not sure I understand your statement that this is not a COBOL issue. We have used this structure in other languages (like C) successfully since the fully qualified name is expected. But I understand that COBOL allows what I would call flexible qualification and therefore cannot determine uniqueness for my case.

Re: Is there a way to force fully qualified variables

PostPosted: Fri Nov 04, 2016 7:25 pm
by Robert Sample
It is not a COBOL issue because you could have allowed both EEE variables to be referenced -- for example, changing BBB from level 02 to level 07 and increasing the level number of the DDD under BBB to at least 08 would allow you to qualify EEE OF BBB and EEE of CCC. So the issue arises due to YOUR coding technique, not anything inherent in COBOL.

And it is totally irrelevant whether or not other languages allow you to do this -- you are dealing with COBOL, which was designed in 1959, so you have to deal with COBOL as it is (unless you give up writing in COBOL and use whatever other language allow you to do this).