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.

BY REFERENCE (the default)

Prog_A: 
1 A  PIC X(4)               value 'abcd'..
1 B  PIC S9(9) Binary value 3000.
Procedure Division.
Call Prog_B using A, B
display B                 *> = 1066
display A                 *> = "ty"

Prog_B:
Linkage Section:
1 X PIC X(4).
1 N PIC S(9) Binary,
Procedure Division.
Display X                 *>  = 'abcd'
Display N                  *> = 3000
compute N = 1066
move 'ty' to X
goback.

BY CONTENT

Prog_A: 
1 A  PIC X(4)              value 'abcd'..
1 B  PIC S9(9) Binary value 3000.
Procedure Division.
Call Prog_B using BY REFERENCE A, BY CONTENT B
display B                 *> = 3000       *> Not changed by the subroutine
display A                  *> 'ty'             *> Changed by the subroutine

Prog_B:
Linkage Section:
1 X PIC X(4).
1 N PIC S(9) Binary,
Procedure Division.
Display X                  *>  = 'abcd'
Display N                  *> = 3000
compute N = 1066
move 'ty' to A
goback.

----------------------------------------------------------------------
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