View previous topic :: View next topic
|
Author |
Message |
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Hi Folks,
I would like to pass a Pointer to a sub-modul.
Does it matter whether where the area is definded (Working or Linkage in main program), to assing the address of this area to the pointer ?
Example 1:
SET POINTER-FIELD TO ADDRESS WS-FIELD
Example 2:
SET POINTER-FIELD TO ADDRESS LS-FIELD
What is different between example 1 and 2 ?
Thanks for help in advance |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I'm not completely sure what you are asking.
It certainly doesn't matter to COBOL, but that doesn't guarantee that you program will work.
Can you give an example of what you are trying to do, and why? |
|
Back to top |
|
|
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Hello Bill,
well, I try to explain...
I have a sub program (dispatcher), it's called from many MPP's running in IMS. The MPP's pass a flag and a pointer via Linkage to the dispatcher when calling.
The flag tells the dispatcher, which next sub program it has to call, passing the pointer comming from MPP.
The pointer containing the address of a copybook from the MPP.
Each MPP calling the dispatcher has a different copybook, with different length.
To have not different 01 levels for each copybook in Linkage (dispatcher) and not a long parmlist in MPP when calling the dispatcher, I decide using a pointer.
My question above concerning assing the address of the copybook in MPP (Linkage or Working) to the pointer.
I hope you understand what I'm trying to do. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
MPP1
Code: |
01 record-area-1 PIC X(20).
01 flag-for-call PIC X VALUE "1".
CALL despatcher USING record-area-1 flag-for-call |
MPP2
Code: |
01 record-area-2 PIC X(300).
01 flag-for-call PIC X VALUE "2".
CALL despatcher USING record-area-2 flag-for-call |
Despatcher
Code: |
LINKAGE SECTION.
01 general-record-area PIC X.
01 flag-of-caller PIC X.
PROCEDURE DIVISION USING general-record-area flag-of-caller.
IF condition-for-calling-program-1
CALL program-1 USING general-record-area
END-IF
IF condition-for-calling-program-2
CALL program-2 USING general-record-area
END-IF |
You can also have all your record-areas REDEFINES each other (except the first) in the LINKAGE SECTION of the Despatcher, but not necessary.
This is how we would do it before POINTERs were available,
Doing it with POINTERs will work, but you'll need more code, so more chance of error, and more "difficult" to understand and maintain.
On CALL ... USING ... and PROCEDURE DIVISION USING ... the lengths of records are irrelevant, since only the start address of the record is passed between the programs. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
On CALL ... USING ... and PROCEDURE DIVISION USING ... the lengths of records are irrelevant |
This is almost true. An issue can arise when the calling program passes an area larger than 4096 bytes and the subprogram expects less than 4096 bytes. An addressing exception can occur due to the mismatch between the programs -- I've had this happen back in the late '90s. I'm not sure if COBOL handles this okay now or not, but I suspect the issue could still occur as it has to do with assembler's 4096-byte base register limitation. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Program VAR1
Code: |
01 PROGA PIC X(50000000).
CALL "VAR2" USING PROGA |
Program VAR2
Code: |
LINKAGE SECTION.
01 PROGB PIC X.
PROCEDURE DIVISION USING PROGB.
CALL "VAR3" USING PROGB
|
Program VAR3
Code: |
LINKAGE SECTION.
01 PROGC PIC X(50000000).
PROCEDURE DIVISION USING PROGC. |
CALL "VAR3" USING PROGB
This will never, now or in the past, cause a problem.
Of course, if PROGC is defined as longer than 50000000 and the bit that is longer is actually referenced there may, or may not, be a S0C4.
Making an item shorter in a CALLed program will never cause a S0C4 if the data is referenced. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Keep in mind that obtaining the address of a non-01 and/or non-77 level LINKAGE SECTION field was introduced with OS/390 COBOL V2.2.
If you're on any version of Enterprise COBOL, then you're covered.
HTH.... |
|
Back to top |
|
|
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Sorry for my late respond for your advise.... many thanks to all !
I will think about your suggestion
@Bill We're using Enterprise COBOL |
|
Back to top |
|
|
|