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
 

 

Cobol and Pointers

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

New User


Joined: 24 Aug 2006
Posts: 3
Location: USA

PostPosted: Thu Jan 30, 2014 1:44 am    Post subject: Cobol and Pointers
Reply with quote

I am a HLASM developer. However I have need to use Enterprise COBOL.

I want to pass to arguments and I know I need to use the linkage section. That is the easy part.

One of the elements in one of the pass structures is a ADDRESS Pointer, and I want to use it since it points to an area in CSA. How can I address that area in COBOL?

The last time I wrote COBOL I used BLL Cells and the New Enterprise COBOL has some new features I don't know how to use.

Thanks in Advance
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Thu Jan 30, 2014 3:31 am    Post subject: Reply to: Cobol and Pointers
Reply with quote

Define it as USAGE POINTER, no PICture.

Define your structure in the LINKAGE SECTION (do not include that in the PROCEDURE DIVISION USING ...).

Then use SET to connect the two together:
Code:


LINKAGE SECTION.

01  a-nice-name-for-the-pointer USAGE POINTER.

01  your-structure.
    05  sub-structure-1 PIC ...
    05  sub-structure-2 PIC ...

PROCEDURE DIVISION USING a-nice-name-for-the-pointer.

    SET ADDRESS OF your-structure TO a-nice-name-for-the-pointer


Then you can use your-structure and its subordinate fields for whatever you want.

Bear in mind that simply defining it as linkage between the two program may do what you want. If you use the pointer in the ASM and then pass the address, you can just put that on the PROCEDURE DIVISION USING ... and define the structure in the LINKAGE SECTION and you are good-to-go. Your choice.
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: Thu Jan 30, 2014 3:44 am    Post subject: Reply to: Cobol and Pointers
Reply with quote

Steve,

Like Assembler, COBOL builds a parmlist of addresses, which points to R1.

When the called sub-program is invoked, it obtains addressability to the parmlist by pointing to R1 (pretty standard stuff). When the sub-program is COBOL, all of this is done under the covers.

COBOL (like Assembler) will set the top high-order bit of the left-most byte of the last parmlist address to B'1000' (X'8'), so you can verify that you've received all of your arguments.

COBOL does employ a means to OMIT a parm (keyword is OMITTED), but I always set up a dummy one-byte field (WS-OMIT, initialize to X'00') as this has always worked for me in the past. I've used this when the called sub-program is invoked in a CICS environment (DFHEIBLK, DFHCOMMAREA, third-parm) as opposed to Batch (one-parm).

If you're passing a POINTER to the sub-program, when the COBOL sub-program obtains addressability, you've then received the ADDRESS of a POINTER-ADDRESS (this should make sense).

All and all, it should be a non-event.

Anything else, just let us know.

HTH....

Regards,
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: Thu Jan 30, 2014 4:23 am    Post subject: Reply to: Cobol and Pointers
Reply with quote

Bill,

If storage has not been allocated in the Caller's LINKAGE for the POINTER, I'm not too sure this will work and may raise a S0C4 Protection Exception.

Ideally, the structure POINTER can be defined to WS, set to the address of the structure and passed as an argument to the sub-program or the structure itself can be specified in the CALL USING, as once the sub-program is invoked, the structure's address can be addressed directly, as it will exist as one of the parmlist addresses off of R1.

Maybe I've misunderstood?

Off topic: For those with long commutes, because of the Ice-Storm, it took me nine hours to get home last night (actually arrived at 1:30am Atlanta time this morning).

Luckily, I had an empty 24oz coffee cup in the car (Posthumous thanks Keith Kalland, wink wink, nod nod). icon_wink.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Thu Jan 30, 2014 4:33 am    Post subject: Reply to: Cobol and Pointers
Reply with quote

Bill,

I was reading it as ASM calling the COBOL program. The pointer passed from the ASM, named on the PROCEDURE DIVISION USING ... and then the "structure" given addressability by using SET ADDRESS OF ... TO pointer-from-the-USING.

With the alternative of doing the pointer-value-to-actual-location in the ASM and just getting it to the COBOL program as a normal parameter.

With no storage defined for the pointer, or it not passed to the COBOL program, yes, it will flat-out fail with a S0C4, when lucky, or trash something up with random areas of storage, when unlucky...

I did assume that the pointer exists in the ASM program. If it doesn't either the whole thing is moot or I completlely missed something :-)
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