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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return results from a "CALL"ed program

Status
Not open for further replies.

SiouxCityElvis

Programmer
Jun 6, 2003
228
US
I am writing a cobol app that will read a named pipe file, and based off of information from the pipe, using CALL to other COBOL programs to process information.

I am able to do this, but I was wondering how I would then return results information back to the program that did the CALL. The called program gets the results, but how does the called program "CALL" back the results?

Thanks in advance.
-David
 
P.S.
I've tried using GLOBAL for my ws-variables, but from what I can tell, GLOBAL applies to variables within the calling program and variables within the called program that are CONTAINED in the calling program.
 
Hi Amarillo,
The usual way to do this in Cobol is to CALL the sub program and pass to it an area of storage from the main program. Within your sub program you would code a LINKAGE SECTION which would reflect the storage passed by the main program. If you have a specific input and output area, it can be useful to split these up within the storage. For example:

Main Program
============

01 WS-COMM-AREA.
05 WS-INPUT-AREA.
07 WS-INP-FIELD1 PIC X(04).
07 WS-INP-FILED2 PIC X(02).
05 WS-OUTPUT-AREA.
07 WS-OUT-RET-CODE PIC S9(04)COMP.
07 WS-OUT-FIELD1 PIC X(04).
.
.
CALL 'SUBPROGA' USING WS-COMM-AREA

Sub Program
===========

LINKAGE SECTION.
01 LS-COMM-AREA.
05 LS-INPUT-AREA.
07 LS-INP-FIELD1 PIC X(04).
07 LS-INP-FILED2 PIC X(02).
05 LS-OUTPUT-AREA.
07 LS-OUT-RET-CODE PIC S9(04)COMP.
07 LS-OUT-FIELD1 PIC X(04).
PROCEDURE DIVISION USING LS-COMM-AREA.

There are other ways of doing this, but this is by far the most common.

Hope this helps.

Marc
 
Okay.
I've got it working where I can pass the data from the calling program outside to another program(the called program).

But, now I want to pass other data(results found in the called program) BACK to the calling program.
Point A sends Point B info as indicated in your code above.
Now, I want Point B to send Point A info back.
In my test scenario, I've got it working to where Point B does get the parameters passed to it from Point A, and have verified that Point B operates on it and also verified that Point A continues to execute after Point B is called(and does its code).

-Thanks.
 
Hi David,
Sounds as if you are there. So long as you define the areas in the two programs the same, you will get data passed back and forth from one program to the other.

In the earlier example, if the sub program moves a value to LS-OUT-FIELD1 and then returns, the main program will find that value in WS-OUT-FIELD1.

It is not uncommon to pass two separate areas or addresses as in CALL 'SUBPROGRB' USING WS-INPUT-AREA WS-OUTPUT-AREA. In this instance the LINKAGE SECTION of the called program would have two 01 levels and the PROCEDURE DIVISON would have USING LS-INPUT-ARE LS-OUTPUT-AREA.

Marc
 
As Marc points out, David, the CALL interface is a two-way street.

Tom Morrison
 
So, let me get this straight.

Currently in my main program.

WORKING-STORAGE.
01 WS-DISP-VAR PIC X(5).

PROCEDURE DIVISION.
....

CALL SUB-PROG USING WS-DISP-VAR.

Currently in my SUB-PROG...
LINKAGE SECTION.
01 LS-DISP-VAR PIC X(5).
MOVE "HELLO" TO LS-DISP-VAR.
.....
01 LS-DISP-VAR PIC X(5).

I used a display statement of WS-DISP-VAR in my Main program and it does show "HELLO", which means to me that WS-DISP-VAR is finding the "HELLO" since it was moved to LS-DISP-VAR(which is referring to the same field I guess, right?)!!!

I think we have success on this!
Main point being that whatever I put in my CALL USING VARS
must match in length in my PROCEDURE USING VARS length in my SUB-PROG's Procedure and LINKAGE section, right?

This is just a simple test I've been working before I get into my real program's needs.

I will be needing to call a subprogram from my main program with some search criteria, and I will have to return 1 to MANY table records back. So, I need to have those table elements defined in my main program, right and in the Linkage section of my called program the exact same length, OCCURS, etc, right? This would mean I'll need to define my WS-IDX used in the Table elements in both also, correct?

Do you know if RMCOBOL 85 does well passing this many variables back and forth? Or does it cause it to process a lot slower?

Thanks.
-David
 
David,

You seem to have the idea, and have come to correct conclusions.

RM/COBOL will happily do all this. I seriously doubt that you will be able to measure the difference in your application speed. In general, the data are not being pass back and forth. The CALL interface uses a call-by-reference model, so only the addresses of the data areas are passed. So when your sample subroutine executes:
Code:
MOVE "HELLO" TO LS-DISP-VAR.
HELLO is actually being stored in the data area defined in the calling program. There is no data area defined in the called program -- all that a LINKAGE SECTION defintion does is describe how the called program expects the calling program's data area to be defined.

Tom Morrison
 
Awesome. Wow, it all makes sense.
Seems to be similar to method calling used in Java, pass by reference, etc.

Thanks everyone for the clarity given on this!

-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top