Page 1 of 1

Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 5:53 pm
by sinmani
If by mistake while coding I MOVE a working storage variable into LINKAGE area. What will happen??
will I get compilation error?
What when i try to pass values through linkage section?

Re: Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 6:06 pm
by BillyBoyo
If you accidently define something in Linkage which should be in Working-Storage, you won't get a compile error (the compiler doesn't know) but you'll certainly get a run-time error if you attempt to access that storage.

Why don't you try it out, before asking?

Re: Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 6:48 pm
by Robert Sample
Think about the purpose of LINKAGE SECTION. It is defining storage being passed to this program from somewhere else (another program or the system). Hence, there is absolutely no way to know at compile time if a given reference to LINKAGE SECTION variable is valid or not. And at execution time, if there's no memory allocated for those items and you attempt to use them ... plan on an ABEND!

Re: Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 8:36 pm
by sinmani
well actually I tried it out before asking.

I tried modifying the WS variable by moving some value in it and it didn't give me any abend??
Thats what puzzled me :(

Re: Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 8:51 pm
by Akatsukami
sinmani wrote:If by mistake while coding I MOVE a working storage variable into LINKAGE area. What will happen??
will I get compilation error?
What when i try to pass values through linkage section?

I understand you to have coded something like
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  WS-FOO  PIC X(9).
 01  WS-BAR  PIC 9(9).
 LINKAGE SECTION.
 01  PARM    PIC 9(9)
 PROCEDURE DIVISION.
 A-PARAGRAPH.
     MOVE WS-FOO TO PARM
*  SHOULD HAVE BEEN "MOVE WS-BAR TO PARM"

whereas Messrs. Boyo and Sample seem to understand you as having coded
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01 WS-BAR  PIC 9(9).
 LINKAGE SECTION.
 01 PARM    PIC 9(9).
 01 WS-FOO  PIC X(9).
* SHOULD HAVE GONE IN WORKING-STORAGE SECTION.

Please explain which it is.

Re: Linkage area variable declaration

PostPosted: Fri Mar 23, 2012 10:44 pm
by sinmani
The second one!!! :)