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

Obtaining the address of Pointer in COBOL


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

New User


Joined: 22 Nov 2007
Posts: 64
Location: Germany

PostPosted: Thu Oct 23, 2014 2:57 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu Oct 23, 2014 3:29 pm
Reply with quote

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
View user's profile Send private message
oerdgie

New User


Joined: 22 Nov 2007
Posts: 64
Location: Germany

PostPosted: Thu Oct 23, 2014 5:57 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Thu Oct 23, 2014 7:20 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Sat Oct 25, 2014 1:46 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Mon Oct 27, 2014 6:11 am
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Nov 10, 2014 5:07 am
Reply with quote

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
View user's profile Send private message
oerdgie

New User


Joined: 22 Nov 2007
Posts: 64
Location: Germany

PostPosted: Mon Nov 10, 2014 8:50 pm
Reply with quote

Sorry for my late respond for your advise.... many thanks to all ! icon_biggrin.gif
I will think about your suggestion

@Bill We're using Enterprise COBOL
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Routing command Address SDSF to other... TSO/ISPF 2
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top