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
 

 

Obtaining the address of Pointer in COBOL

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

New User


Joined: 22 Nov 2007
Posts: 55
Location: Germany

PostPosted: Thu Oct 23, 2014 2:57 pm    Post subject: Obtaining the address of Pointer in COBOL
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Oct 23, 2014 3:29 pm    Post subject: Reply to: Pointer in COBOL
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: 55
Location: Germany

PostPosted: Thu Oct 23, 2014 5:57 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Oct 23, 2014 7:20 pm    Post subject: Reply to: Pointer in COBOL
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: 7909
Location: Bellevue, IA

PostPosted: Sat Oct 25, 2014 1:46 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Mon Oct 27, 2014 6:11 am    Post subject: Reply to: Pointer in COBOL
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Nov 10, 2014 5:07 am    Post subject: Reply to: Pointer in COBOL
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: 55
Location: Germany

PostPosted: Mon Nov 10, 2014 8:50 pm    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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