Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers in Cobol 1

Status
Not open for further replies.

rustym

Programmer
Aug 9, 2001
11
0
0
US
I am making a small driver program to call another program. I just realized that I need to use pointers. I have been using the following variables:

01 CALLED-PROGRAM-ID PIC X(08) VALUE 'ACMPW067'.
01 RET-VAL PIC 9(02) VALUE 00.
01 IO-AREA PIC X(3200) VALUE '02501BE7436561 /101546945ALLALL000021183577'.

In the driver program, how do I set up some variables as pointers and put some valid info in them prior to sending them off to a called program? I need three pointers. The first one should point to an address which holds a module name like "acmpw022". The second pointer should point to an address which holds a return code... and I want to start it out as 00, which is for successful. The last pointer is for an IO area... the info we want brought back. It will be a mixed string of characters, up to 32000 bytes.

Here's a snippet of the called program:

LINKAGE SECTION.
01 LNK-MODULE-NAME-POINTER USAGE POINTER.
01 LNK-COMPLETION-CODE-POINTER USAGE POINTER.
01 LNK-IO-AREA-POINTER USAGE POINTER.


PROCEDURE DIVISION NTAPI USING LNK-MODULE-NAME-POINTER
LNK-COMPLETION-CODE-POINTER
LNK-IO-AREA-POINTER.

Any help would be greatly appreciated.
Thanks,
Rusty
 
You need not use POINTER at all in this situation. COBOL uses call-by-name (USING ... BY REFERENCE in COBOL terms), so modify your called program:

Code:
LINKAGE SECTION.                                          
01  LNK-MODULE-NAME              pic x(8)
01  LNK-COMPLETION-CODE          pic 9(02).           
01  LNK-IO-AREA                  x(3200).           
                                                          
                                                          
PROCEDURE DIVISION NTAPI USING LNK-MODULE-NAME    
                               LNK-COMPLETION-CODE
                               LNK-IO-AREA.
(Some confusion: in the code sample you use 3200, but your description says 32000.)

Most implementations pass an address/pointer across the calling boundary, but that is invisible to the COBOL programmer.

Tom Morrison
 
Hi Rusty,

A point of confusion on my part:

You show the called pgm name both in the caller and the called pgm. Why?

Code:
Should the call stmt be: 
CALL CALLED-PROGRAM-ID USING RET-VAL    
                             IO-AREA               
and the LINKAGE area be:

01  LNK-COMPLETION-CODE     pic 9(02).           
01  LNK-IO-AREA             pic x(3200).

or is the sub-pgm going to call the pgm in
LNK-MODULE-NAME?

Another fine point: you may want to define RET-VAL as
pic xx val '00' in the CALLer. Reason: If the sub-pgm fills RET-VAL with a non-DISPLAY data type, it can cause your CALLer pgm to abend if the field is referenced after the return from the CALL.

HTH, Jack.




 
Thanks Tom and Jack, your responses helped a lot!

Tom, after following your suggestion, things seem to work better. I have compiled each project to INT code. (Did I tell you that I'm using Micro Focus Net Express?) However, when I try to step through my trigger program to the called program, I get two message boxes: The first tells me that "The IDY file (of the same name as the CBL file I'm trying to step into) does not contain any info for debugging GNT or OBJ code. You cannot step through this program..." This message has two buttons, one to Run Thru the code, the other to Stop Animating. When I click the Run Thru button, I get the second message box, which says: "Execution of the program EASLBRDG has been interupted. This program is not animatable, but you can view the call stack. The cause of the interrupt was: 114 Attempt to access item beyond bounds of memory."

When I recompile the called program to GNT code and start again to step through from my trigger program, I get the second of the two message boxes mentioned above.

Should I have the trigger program and the called program compiled to the same type code? I don't think you can animate with OBJ code?

Again, thanks for your help,
Rusty
 
Rusty,

I am not familiar enough with the Micro Focus product to be able to help.

I would suggest starting another thread now that you are having a debug problem rather than something that has to do with pointers. Make sure you mention Net Express in the title, so that appropriate experts will be able to find it.

Best regards,
Tom Morrison
 
I believe that you will still need to use pointers, because the arguments are defined as pointers. To create a pointer, code something like this:

01 LNK-MODULE-NAME-PTR USAGE POINTER.

then you should be able to fill it in the PROCEDURE DIVISION with this code:

SET LNK-MODULE-NAME-PTR TO ADDRESS OF LNK-MODULE-NAME-PTR.

Hope this helps, Betty Scherber
Brainbench MVP for COBOL II
 
Thanks, Betty. That was right on the mark.

Did you have any thoughts on the '114 Attempt to access item beyond bounds of memory' warning? Am I doing something wrong which is not allowing me to call the function in the external DLL?

Rusty
 
Well, I'll wade back into this.

Betty's suggestion sets the pointer to point at itself. An out of bounds reference seems to me to be an expected result.

Rusty, a better approach to solving this problem would be for you to describe what you are trying to accomplish, rather than you so-far-unsuccessful solution. Using pointers in COBOL is rarely called for in normal programming. Sometimes there is a better way... :)

Tom Morrison
 
Rusty,

I was at first hesitant to respond to this post because my experience with MicroFocus was over two lifetimes ago.

Anyway, I think I will agree with Tom's initial reaction to your query in that you probably do not need pointers in this case.

And then I will agree with Tom again: give us more info - what are you trying to accomplish - and then perhaps we can be of better help.

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top