View previous topic :: View next topic
|
Author |
Message |
vaduguru
New User
Joined: 07 May 2005 Posts: 5
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
It was my hope that vaduguru would reply first with more info about what is really wanted. . .
If what was wanted gets posted, we can advise on how to accomplish. . .
Definition versus usage. . . |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
We've got 3 questions for the price of one!
- in the title: Difference between ws variable and linkage section variable: huge difference.
- in line 1: What is the difference in declaration: little differences (you can't use VALUE in LS).
- 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 |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
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 |
|
|
manikawnth
New User
Joined: 07 Feb 2007 Posts: 61 Location: Mumbai
|
|
|
|
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 |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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
Quote: |
BUT keep up the good work inspite of that. |
Thanks
d |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
|