Thanks for the reply, and I am already familiar with the differences between BY 
VALUE and BY REFERENCE.  In my particular case all CALL parameters are BY 
REFERENCE (by default, no BY phrases are used), and I expected the nested 
COMMON subprogram to use the address passed in the call that referred to the 
structure passed by the outermost program.  None of the same-named structures 
are declared GLOBAL.

But I also expected the compiler to recognize while processing the code in the 
nested subprogram that references to the same-named structure fields in the 
nested subprogram were in fact intended to be references to the structure 
defined in the LINKAGE section of that nested subprogram (i.e., use the 
"nearest" field definition, not the outermost one), and not direct references 
to the same-named structure fields defined in the in the outermost program.  It 
was a surprise to me that the compiler did not assume that it should use the 
LINKAGE section definition

In any case, the same storage area is referred to, and changes made by the 
nested subprograms do indeed change the value as seen in the outermost program, 
and that was the intended result.

Peter

-----Original Message-----
From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of Jon 
Butler
Sent: Thursday, October 14, 2021 8:12 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: COBOL 6.2 - use of identical data name in a nested COMMON 
subprogram generates a IGYPS0037-S compiler error

The Linkage Section is how modules pass data from the top module in the chain 
down, and then back.  In fact, they don't "pass" the data at all, but use a 
single address that is established by the top-most caller.  All modules use the 
same address which is located in the top-most module's DSECT, irrespective of 
the variable's name...although in your case the name is the same in both caller 
and called module.  This is how external CALLs work.  

As you note, INTERNAL calls establish a new variable unless the GLOBAL 
attribute is applied.  Why the compiler was built that way is an interesting 
question perhaps Tom Ross can answer.  Remember, internal subroutines are 
relatively new in COBOL, but even so, you are asking the question some 20 years 
too late.  BY CONTENT may be what you want in the CALL statement.

You can override the standard behaviour ( BY REFERENCE) by using BY CONTENT, 
where the called module can change the value locally, but not affect the 
caller; or by using BY VALUE (not recommended by me) where the value is passed 
and the called module can change the format as long as it's commensurate, e.g. 
Binary to  Fixed Decimal or Float (comp-2).  You can mix CONTENT, REFERENCE and 
VALUE in the same call for different variables.

<Code samples snipped>
--

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to