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!

Variables not re-intializing 2

Status
Not open for further replies.

SiouxCityElvis

Programmer
Jun 6, 2003
228
US
I'm on RMCOBOL-85 on Linux.

I have a parent program running as a server.

It calls a child program.
In the Parent Program...
PROCEDURE DIVISION.
...
...
A pipe msg is read,
...
CALL "CHILD.COB"
...
Go back to the top and read for more pipe msgs(A loop on the pipe read in other words - a pseudo "server").
...
...
in Child prg.
IDENTIFICATION DIVISION.
PROGRAM-ID. CHILD.
...
..
WORKING STORAGE.
WS-INCREMENT PIC 9(3) VALUE 0.
PROCEDURE DIVISION.
..
..
DISPLAY WS-INCREMENT.
ADD 1 TO WS-INCREMENT.
GO TO END-IT.

END-IT.
END PROGRAM CHILD.
...
..

My question regards the WS-INCREMENT variable no re-initializing to value 0 each time the CHILD is called.
My DISPLAY Statement should always show "0", but does not, it increments. Shouldn't the "calling" of the Child program show a 0 everytime the Child program is called?
Especially since I have the END-IT procedure which "ends" the PROGRAM "CHILD"???

I'm lost...
Any help would be great.
Thanks.
-David
 
Called program keep their variable state within calls except on the following situations

1- A cancel is issued after the call.
2- INITIAL clause is mentioned on the PROGRAM-ID.
(From the manual ..
PROGRAM-ID. {program-name or literal IS [ {INITIAL or COMMON} PROGRAM]
....
The INITIAL clause specifies that the program is initial. When an initial program is called, it and any programs contained within it are placed in their initial state. When an EXIT PROGRAM or GOBACK statement is executed in an initial program, the program is implicitly canceled.

So your program is behaving correctly.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
So, if I use the initial clause, the Linkage will still hold the parameter values passed to it from the calling program, right?
And when control is passed back to the calling program, the parameter values will be as the called program modified them to be, correct?

I don't seem to remember running into this problem before and I've got other projects that do the same type of thing, but I'll look into this INITIAL clause more.
 
Linkage is another type of fish.

It will be dependent on how the calling program passed the variables.

You can use

call pgm using
by reference vx
or
by content vx

or
vx

If vx is a literal then it is always considered as a "by content".

If it is a variable it will depend on which option was used, and if neither then it will be considered as "by reference
".

Note that if you have a string of using like follows

call pgm using
by reference
v1 v2 v3
by content v4
by reference
v5
by content
v6 v7 v8

v1, v2, v3 and v5 are all passed by reference
. e.g. the previous explicit or implicit option is considered.


So on your answer if by refernce is used then the variables passed to and changed by the called program will hold the passed value and will return the changed value.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Okay, the IS INITIAL on the PROGRAM-ID part seemed to take care of my problem.

I have created the habit of passing by ref I guesss.

What I've always done is
CALL WS-SUB-PGM USING
WS-THIS-ONE
WS-THAT-ONE
WS-ALL-OF-EM

So, in the called program in the it's linkage section having:
LS-THIS-ONE
LS-THAT-ONE
LS-ALL-OF-EM

If I modify any of the LS- vars, then their corresponding WS- vars in the calling program will retain the changed value, correct?

Thanks.
-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top