First next. In terms of working store GLOBAL is an all programs in tree scope modifier, in WORKING-STORAGE, the name accessible to nested programs. EXTERNAL sets up a run-time managed list of identifiers, shareable by all programs regardless of scope.
Independently compiled callable programs can use EXTERNAL, as long as they are part of the current libcob. This is relatively expensive, as it's a run-time address resolution, and consistent sizing is the responsibility of the programmer. An error will be raised at run-time if the sizes are not identical for all EXTERNAL address requests. GLOBAL is faster compile/link loader time, and is meant for in source nested program groups.
GLOBAL gets more complicated with file definitions, but that's almost a separate topic.
There is, of course, more to it in the edge cases of COBOL. ;-)
Cheers,
Blue
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
What 's the difference between use Global versus External?
A bad use of this statement can create bugs?
Thank for your help.
Last first. Yep.
First next. In terms of working store GLOBAL is an all programs in tree scope modifier, in WORKING-STORAGE, the name accessible to nested programs. EXTERNAL sets up a run-time managed list of identifiers, shareable by all programs regardless of scope.
Independently compiled callable programs can use EXTERNAL, as long as they are part of the current libcob. This is relatively expensive, as it's a run-time address resolution, and consistent sizing is the responsibility of the programmer. An error will be raised at run-time if the sizes are not identical for all EXTERNAL address requests. GLOBAL is faster compile/link loader time, and is meant for in source nested program groups.
GLOBAL gets more complicated with file definitions, but that's almost a separate topic.
There is, of course, more to it in the edge cases of COBOL. ;-)
Cheers,
Blue
You can read about it (with small examples) in "GnuCOBOL Programmers Guide":
https://gnucobol.sourceforge.io/guides.html
--> 11.6. Sharing Data Between Calling and Called Programs
László