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

Cobol and Pointers


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Thu Jan 30, 2014 3:31 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 30, 2014 3:44 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 30, 2014 4:23 am
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

Moderator Emeritus


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

PostPosted: Thu Jan 30, 2014 4:33 am
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 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 Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top