This is one of the most obscure concepts in Cobol-dom; The concept of
a run unit. I assume you're talking about OPM Cobol (aka Cobol/400).
You see, Cobol has the concept of a run unit. In OPM here's how it
works. The first Cobol program in the call stack is designated the
Main program of the run unit. In your case the RPG program calls a
Cobol program. Well, guess what? RPG is out of the run unit. Any
subsequent calls are also considered to be part of the run unit. So if
the so-called main (or first) Cobol program calls another program (of
any language), that too is considered part of the run unit. Here is
what I mean.
RpgPgm calls CobolPgm1, calls AnyKindOfPgm2, etc.
so RpgPgm is not in the run unit. CobolPgm1 is the main program in the
run unit. And every program forward from CobolPgm1 in the call stack
is also considered part of the run unit. Again, this is all OPM.
Things change and get quite a bit more confusing if you introduce an
ILE program written in ILE C, ILE Cobol, RPG IV, or ILE CL into the
mix.
If any Cobol program (main or otherwise) issues a Stop Run, it ends
the entire run unit. In your case, the RPG program would not be ended
because it is outside of the run unit. Also, when the main program
ends in any way (Stop Run or GoBack), this too ends the run unit. When
the run unit ends, all the programs in it are deactivated. All memory
associated with the run unit is deallocated, all files are closed etc.
There is no way given your setup to make the files stay open when the
RPG program gets control.
There is a solution to your problem if you are willing to compile your
Cobol programs as ILE Cobol programs. If you're interested in that, I
can expand. Otherwise, you're out of luck.
Please visit us at NEWS/400's Cobol Community Forum where I and others
answer questions such as yours all the time. Point your browser at
http://www.news400.com/redir/redir.cfm?story=/cobol/index.htm and
click on Cobol Forum. Btw, a $50 prize is awarded monthly for the best
Cobol tip for that month. Plus we publish your tip as the tip of the
month. Things have been slow lately and there really have been no tips
posted for about 2 months now. So anybody that wants F & F (fame and
fortune) visit us at the forum and post your ideas. Of course, the
thing is somewhat subjective as the sysop (me!) must decide if I think
it is worthy. But it's worth a try, right? Usually, the winners are
simply answering somebody else's questions. However, you can simply
post an unsolicited tip if you think it might be of general interest.
See you there!
Mike Cravitz
NEWS/400 Technical Editor
Mike Cravitz wrote:
> There is a solution to your problem if you are willing to compile your
> Cobol programs as ILE Cobol programs. If you're interested in that, I
> can expand. Otherwise, you're out of luck.
>
The old method we used to get around this was to write a very small COBOL
program as the initial program, that simply called the previoius initial
program (in your case the RPG). That way there is always a COBOL run unit
in the stack.
You can do this real quick, while you convert you COBOL to ILE COBOL.
Olga wrote in message <35DDA084...@ibm.net>...
>We call a Cobol program, that leaves files opened and ends with GOBACK
>instruction, because we need call it several times from other program.
>When a Cobol program calls this program, the files remains opened when
>return, but if a RPG program calls the same program, the files aren't
>opened when return to the RPG program. Can anybody help me?
>Thanks.
>Olga
>
--
David Abramowitz
>The old method we used to get around this was to write a very small COBOL
>program as the initial program, that simply called the previoius initial
>program (in your case the RPG). That way there is always a COBOL run unit
>in the stack.
Good idea. That works.
>PLI uses the same concept of run unit and we solve the problem by using
>OVRDBF with SHARE(*YES) and opening the file in the RPG program prior to
>calling the PLI program. this same should work in COBOL
This should work fine. Whoever uses this technique needs to be aware
that using this technique (shared ODP) means you must never make any
assumptions regarding file positioning at program startup or upon
return from a call.
>Try using EXIT PROGRAM instead of GOBACK.
Ahh! You're right...but you didn't finish the thought. In ILE Cobol
you can code Exit Program and Continue Run Unit (V3R7 and higher).
This will solve the problem also.
Olga
David Bye escribió:
> Mike Cravitz wrote:
>
> > There is a solution to your problem if you are willing to compile your
> > Cobol programs as ILE Cobol programs. If you're interested in that, I
> > can expand. Otherwise, you're out of luck.
> >
>
> The old method we used to get around this was to write a very small COBOL
> program as the initial program, that simply called the previoius initial
> program (in your case the RPG). That way there is always a COBOL run unit
> in the stack.
>
Olga.