IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Can we use linkage section variables in Arithmetic operation


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Chiranjeevi9

New User


Joined: 14 Dec 2011
Posts: 11
Location: India

PostPosted: Thu Apr 12, 2012 8:53 pm
Reply with quote

Hi,

i have a question,

Can we use the linkage section variables in Arithmetic operations?

I have tried to search in different books. i didn't get it.
Practically, i have tried in two different systems. one system has accepted the arithmetic operations and another didn't accepted to do the arithmetic operations with linkage variables.

Please let me know the answer.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 12, 2012 8:57 pm
Reply with quote

Of course you can use LINKAGE SECTION variables in arithmetic operations. However, it is up to you to ensure that the LINKAGE SECTION variables CAN be used at all -- by using them only after having PROCEDURE DIVISION USING .... in your code. and actually setting up your execution to define storage for the variables.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Apr 12, 2012 8:59 pm
Reply with quote

How could you possibly not be able to, subject to Robert's points?

Can you show us the one that "didn't work"?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Apr 12, 2012 10:23 pm
Reply with quote

If addressability hasn't been established to the Linkage Variables, you'll get a S0C4 Protection Exception as soon as you attempt to use them.

Linkage Variables are akin to Assembler DSECT's.
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Thu Apr 12, 2012 11:11 pm
Reply with quote

From your post I read:
Quote:

Practically, i have tried in two different systems. one system has accepted the arithmetic operations and another didn't accepted to do the arithmetic operations with linkage variables.


I hope the systems you refer to are z/OS or equivalent.
Did you understand the message produced by the compiler?
It says clearly, as in this message:

IGYSC2025-W "NUM1" or one of its subordinates was referenced, but "NUM1" was a
"LINKAGE SECTION" item that did not have addressability. This reference
will not be resolved successfully at execution.

Pls note the W in the message id, which indicates a Warning and gives a return-code of 4.
The message from the compiler will dissapear if you have a Procedure Division Using Num1 .
This is what Bill just mentioned.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Apr 12, 2012 11:44 pm
Reply with quote

Peter,

Some shops (for whatever reason) suppress W errors and only consider E and above and I think it's foolhardy.

IMHO, the compile option FLAG(I,I) should be specified, regardless, because W's are raised when (for example) a LINKAGE item is not included in the PROCEDURE "USING" and the (non)addressability message is raised.

An area that always should be addressed are redefined LINKAGE fields, where a redefined field exceeds the length of the field of which addressability is established and someone tries to use the longer field, but gets a S0C4. This type of redefine inconsistency error will be raised, either as an I or a W during compilation.

Bottom line is this; LINKAGE and WORKING-STORAGE are two entirely different sections, with LINKAGE being the more volatile.

Regards,
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 12:31 am
Reply with quote

I completely agree with Mr Bill about compiler messages. List them all. Check them all. Fix them all, if at all possible. I've been bitten personally by ignoring them and don't know anyone who hasn't. Once bitten, you know better.

The redefines which is bigger usually indicates a problem. In the working-storage, these days, it even generates extra storage. Having seen enough redefines which are too long, and none of them coded deliberately, they should always be fixed and almost exclusively are themselves wrong. They will not, in themselves, cause S0C4.

Not to forget that PROCEDURE DIVISION USING is no longer the only way of establishing addressability. If addressability is your problem and the items are not passed to you on a CALL, then you need to do something else, but without showing us the code in question it is difficult to hand-off to you what might turn out to be a bomb on a trigger-fuse.
Back to top
View user's profile Send private message
Chiranjeevi9

New User


Joined: 14 Dec 2011
Posts: 11
Location: India

PostPosted: Fri Apr 13, 2012 4:32 pm
Reply with quote

Hi,

Thanks for the answers.

Hi Bill Woodger,
in plain COBOL program, if i use linkage variables in arithmetic operations, i didn't get any error.

In COBOL-CICS program, i got the Abend while runtime. When i removed the arithmetic operations on linkage section variables, it went through fine.

Long back, i read some where that, Linkage variables can not be used in arithmetic operations. i don't remember where i read, i am not able to find in google also now. Because of the above issue and my old bookish knowledge i got confused.

But, i got the answer from you that, we can use the linkage variables in arithmetic operations.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Apr 13, 2012 7:04 pm
Reply with quote

I'm scratching my head and wondering how you came to this conclusion, without understanding all that we have explained, unless you have left out all the major considerations. icon_rolleyes.gif

Apparently, you're going to have to learn from your assumptions....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 8:38 pm
Reply with quote

Hello,

Quote:
Long back, i read some where that, Linkage variables can not be used in arithmetic operations.
As is proven over and over - one must be very careful about what one believes from some "reading" . . . Much that is available (especially via the internet) is simply wrong and worthless. Some is misunderstood due to an author's choice of wording or confusion by the reader.

Learning a few reliable and easily understood sources is better than grabbing "stuff" from just anywhere.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts JCL with variables JCL & VSAM 1
No new posts FD Section to Create FB or Vb File Dy... COBOL Programming 1
No new posts JCL Variables JCL & VSAM 1
Search our Forums:

Back to Top