Page 1 of 1

GNU COBOL compiler and the zOS COBOL complier. GNU wins?

Posted: Thu Nov 05, 2015 2:59 pm
by Prakash Jha
Hi,

I was running some COBOL progrms using GNU COBOL to see how it all goes. The results are pretty good so far however I have run into one glitch which is confusing me. It is in a data definition. Please consider this example:

Code: Select all

01 AA 
     10 BB 
          15 CC1 
          15 CC2 
      12 DD 
           15 EE1 
           15 EE2 
       10 FF 
The GNU COBOL compiler shows an error on the "12 DD", the error message:

Code: Select all

Warning: No previous data item of level 18 
This message seem correct to me. While the compile listing on z/OS does not does not have any error flagged like this. I think, IBM compiler has inserted a FILLER type entry to make the above look like:

Code: Select all

01 AA 
     10 BB 
      12 FILLER 
          15 CC1 
          15 CC2 
       12 DD 
           15 EE1 
           15 EE2 
       10 FF


Does anybody know, for sure, what the IBM compiler is doing with this?

Re: GNU COBOL compiler and the zOS COBOL complier. GNU wins?

Posted: Thu Nov 05, 2015 6:38 pm
by Robert Sample
You did not post enough information -- which of the variables have PICTURE clauses? As posted, if 12 DD does not have a PICTURE then it is a group variable and the structure is valid COBOL, and GNU COBOL is erroneously generating a message.

IBM COBOL will modify a structure if needed (see slack bytes in the Enterprise COBOL Language Reference and Language Guide manuals) but I'm not sure it would make the change you think is happening.

Re: GNU COBOL compiler and the zOS COBOL complier. GNU wins?

Posted: Thu Nov 05, 2015 6:45 pm
by William Collins
Well, if you look at your compiler output listing, you'll know, for sure, what the compiler has done, and it is not what you think.

If you look at Appendix A in any Enterprise COBOL Language Reference you'll find this, under DATA DIVISION:
Specifying level numbers that are lower than other level numbers at the same hierarchical level in a data description entry. [Standard COBOL 85 requires that all elementary or group items at the same level in the hierarchy be assigned identical level numbers.]
Your fist level-10 defines a hierarchy which is ended by your second level-10. You then have level-15, which is subordinate to the level-10, another level-15, then the level-12. The level-12 is subordinate to the level-10, but not subordinate to the level-15. So it must be equivalent to the level-15. The Enterprise COBOL compiler "normalises" level-numbers, so if you look at your compile listing you'll see that those two level-15s and the level-12 all appear as level-3, with the level-15 subordinate to the level-12 normalised as a level-4.

I think you've quoted your GnuCOBOL message from an earlier version of your code or made a typo, the message would refer to level 12, not 18.

So, both the Enterprise COBOL compiler and the GnuCOBOL compiler are correct. They are just applying different rules, due to the IBM Extension to COBOL detailed above.

This assumes that all your level-15s are individual items defining storage.

Re: GNU COBOL compiler and the zOS COBOL complier. GNU wins?

Posted: Wed Nov 11, 2015 9:31 am
by Prakash Jha
Thank you so much William for the explanation. It is much clear now.