Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Difference between ws variable and linkage section variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vaduguru

New User


Joined: 07 May 2005
Posts: 5

PostPosted: Wed Mar 24, 2010 7:55 am    Post subject: Difference between ws variable and linkage section variable
Reply with quote

Hi All,

What is the difference in declaration of working storage variable and linkage section variable apart from the passing values from one program to other program. Suppose I want to declare VAR-A PIC X(10) in both WS and LS. Please let me know.
Back to top
View user's profile Send private message

dick scherrer

Site Director


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

PostPosted: Wed Mar 24, 2010 8:18 am    Post subject:
Reply with quote

Hello,

There is no difference in the definition of the variables. They would have to have different names to be easily referenced in the code.

If you clarify what you are looking for, someone may have a more useful answer.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Wed Mar 24, 2010 4:32 pm    Post subject:
Reply with quote

There is one difference to be aware of. From the COBOL Language Reference manual, section 5.1.4 on Linkage Section:
Quote:
Record description entries and data item description entries in the linkage section provide names and descriptions, but storage within the program or method is not reserved because the data area exists elsewhere.
Your VAR-A definition in LINKAGE SECTION is not actually usable without allocating storage for it in some way.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Wed Mar 24, 2010 7:04 pm    Post subject:
Reply with quote

From my experience another difference is with regard to DB2 host variables.

If you refer to a host variable in sql like:

EXEC SQL
SELECT .....
WHERE TAB.VAR1 = :WS-VARA
END EXEC

The host variable (:WS-VARA) can not be in the linkage section.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Mar 24, 2010 7:18 pm    Post subject:
Reply with quote

daveporcelan wrote:
From my experience another difference is with regard to DB2 host variables.

If you refer to a host variable in sql like:

EXEC SQL
SELECT .....
WHERE TAB.VAR1 = :WS-VARA
END EXEC

The host variable (:WS-VARA) can not be in the linkage section.

Because the DB2 interface should have an explicit pointer to a storage area. A linkage section entry has no base address at compile time, it is a pointer and some offset definitions for storage elsewhere.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Mar 24, 2010 7:37 pm    Post subject:
Reply with quote

Hello,

It was my hope that vaduguru would reply first with more info about what is really wanted. . . icon_sad.gif

If what was wanted gets posted, we can advise on how to accomplish. . .

Definition versus usage. . . icon_cool.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Thu Mar 25, 2010 3:16 am    Post subject:
Reply with quote

We've got 3 questions for the price of one!
  1. in the title: Difference between ws variable and linkage section variable: huge difference.
  2. in line 1: What is the difference in declaration: little differences (you can't use VALUE in LS).
  3. in line 2: Suppose I want to declare VAR-A PIC X(10) in both WS and LS: it can be done with some restrictions. Here is an example:
    Code:
    W-S SECTION.
    01  SOME-WS-AREA.
        05 VAR-A   PIC X(10).
        05 VAR-B   PIC X(40).

    LINKAGE SECTION.
    01  SOME-LS-AREA.
        05 VAR-A   PIC X(10).
        05 VAR-B   PIC X(40).
    you access the variables as VAR-A OF SOME-WS-AREA or VAR-A OF SOME-LS-AREA.
    of course, most people would add a prefix to the variables: WS-VAR-A and LS-VAR-A instead.
Back to top
View user's profile Send private message
manikawnth

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Thu Mar 25, 2010 9:52 am    Post subject:
Reply with quote

Hi vaduguru,

There is a huge difference.
When you see the listing the address allocation working storage variables is continuous where as in the linkage section every 01 level variable is started with fresh displacement 0000000.

From this it is inferred that
Working storage data are like variables specific to that program where the memory is allocated to the variables when the program is loaded and the address of the variables cant be WS changed.

Whereas in linkage section each 01 level is like a special register.
As u can load some address into a register (if u have some idea of assembler), u can always assign the address to each 01 level in linkage section. And improper address assignment may lead 0C4 or 0CB abends.
All the variables below each 01 level will be like a mapping the contents from that address (similar to USING DSECT in assembler).

Lemme know if u r clear.

Thanks,
Manikanth
Back to top
View user's profile Send private message
manikawnth

New User


Joined: 07 Feb 2007
Posts: 61
Location: Mumbai

PostPosted: Thu Mar 25, 2010 9:53 am    Post subject:
Reply with quote

And one more thing,

Linkage section means not passing variables from one program to another program.
Actually u r referring to the passed variables address using 01 level in the linkage section
Back to top
View user's profile Send private message
rpuhlman

New User


Joined: 11 Jun 2007
Posts: 80
Location: Columbus, Ohio

PostPosted: Thu Mar 25, 2010 7:26 pm    Post subject:
Reply with quote

Hey Marso,

In regards to:

Quote:
in line 1: What is the difference in declaration: little differences (you can't use VALUE in LS).


I believe you already know this, but you can use the VALUE clause for 88 Levels in the Linkage Section. I just don't want vaduguru to think that you can never use the VALUE clause in the Linkage Section.

Rick
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Apr 19, 2010 6:53 pm    Post subject:
Reply with quote

Quote:
The host variable (:WS-VARA) can not be in the linkage section.


This is UNTRUE

check the manual. Read a little on the web, why it is a problem.
but please, don't make such comments.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Apr 19, 2010 7:18 pm    Post subject:
Reply with quote

Quote:
The host variable (:WS-VARA) can not be in the linkage section.


Quote:
Because the DB2 interface should have an explicit pointer to a storage area. A linkage section entry has no base address at compile time, it is a pointer and some offset definitions for storage elsewhere.


actually both statements are BS. They are NOT TRUE.

as far as the second is concerned,
then what your are saying is the PROCEDURE DIV USING statement
should not work.
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Mon Apr 19, 2010 10:15 pm    Post subject: Reply to: Difference between ws variable and linkage section
Reply with quote

I have not posted many replies to this forum. Therefore the amount of time that I spend helping others in the forum is very low. BUT. for those of you who make the effort and give your time to respond to people's questions; I believe that you deserve at the very least a response from those who post their questions.

I only see a small amount of responses coming back (i.e. "your solution worked") from the people who are asking for help.

BUT keep up the good work inspite of that.

Ridgewalker58
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Apr 20, 2010 2:41 am    Post subject: Reply to: Difference between ws variable and linkage section
Reply with quote

Quote:
I only see a small amount of responses coming back (i.e. "your solution worked") from the people who are asking for help.
Yup, this is a largely a "grab and go" environment. . .

"I got what i wanted and i'm outta here. . ." is not posted, but is very common.

We have issues getting many to even clarify their questions when what is posted is insufficient to provide help icon_wink.gif

Quote:
BUT keep up the good work inspite of that.
Thanks icon_smile.gif

d
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Tue Apr 20, 2010 8:22 pm    Post subject:
Reply with quote

Dbz,

I clearly started my statement ‘in my experience’

At our shop, we have had several cases where a host variable is in the linkage section.

These programs compile and bind successfully.

At run time the program abends (I can not recall the error code)

The solution to the problem:
move var-linkage to var-working-storage
change host variable to use var-working-storage

I suppose there may be another solution derived from the manual.
This may however require a changing in compile options.

My experience was derived from the cause, effect, solution approach.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Apr 20, 2010 8:46 pm    Post subject:
Reply with quote

well, the reason that host variable declare in linkage provide a problem is because people do not understand the code the db2 pre-compiler inserts into a module.

the first instruction inserted is the go to SQL-END if a flag is set.
this flag is set after the code between the first instruction and SQL-END has been executed.

the code in between is nothing else but CALLs to db2 to provide addresses for the data generated by the pre-compiler (inserted between the last programmer working-storage entries and linkage section) and to host variables.

if a linkage section item has no addressability , then you have a problem.
if a linkage section item on the first CALL to the db2 module comes from pgm-a and the second CALL comes from pgm-b, then the address of the host variables (in linkage) has changed, but db2 will not be aware,
because the addressing logic is only executed once - unless the flag is reset by the program.

so, if one wants to employ linkage section host variables you have one of three solutions:

1. code a reset of the db2 flag in your db2 module. problem is that the code will be re-executed each time the program is CALLed, which is a waste.

2. insure that the storage referred to in linkage is always the same. this can be accomplished by only CALLing the db2 module from one particular module and always use that module's working storage. But this is also a waste because you could have many modules that require access.

3. use only one modules working-storage for structures and use pointers in all other modules to provide addressability in linkage.

so, since the solutions require either repeating code, which is a waste,
or require some thought and design, it is easier to not use linkage for host variable.

but, linkage can be used as host variables.

and has nothing to do with changing compile options

as you said, the erroneous conclusion was based on observation of half the story and ignorance of the actual problem.

your solution reminds me of McMillians motto.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Tue Apr 20, 2010 8:53 pm    Post subject: Reply to: Difference between ws variable and linkage section
Reply with quote

Dave,

If you have any experience with Assembler, then an "01" level in COBOL LINKAGE is very similar to an Assembler DSECT.

For example, DFHCOMMAREA.

Code:

DFHCOMMAREA DSECT
            USING *,R7               INFORM ASSEMBLER
COMMAREA    EQU   *
*
CICSPGM     DFHEIENT CODEREG=R3,DATAREG=R13,EIBREG=R11     
            LH    R15,EIBCALEN       PREPARE FOR 'CHI'
            CHI   R15,1              ZERO OR NEGATIVE?
            BL    NOCOMMA            YES, NO COMMAREA
            L     R7,DFHEICAP        ESTABLISH ADDRESSABILITY

In COBOL, there is a similar means to establish addressability and is part of the PROLOG code.

The "01" level is simply a placeholder, which won't point to an area of data until it's told to do so.

LINKAGE items which contain a 'VALUE' clause raise a compiler warning and the VALUE is always ignored.

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sticky: difference between ... DUMMY ... and ... enrico-sorichetti JCL & VSAM 0 Mon Oct 17, 2016 4:31 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts OPC JCL Variable passion_sujesh IBM Tools 5 Fri Jul 01, 2016 4:21 am
No new posts JOINKEYs and Variable files migusd SYNCSORT 8 Fri Jun 17, 2016 3:16 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us