View previous topic :: View next topic
|
Author |
Message |
passion_sujesh
New User
Joined: 14 Mar 2008 Posts: 74 Location: India,Chennai
|
|
|
|
Hi,
I have a doubt in calling a program dynamically. I have an program (prog A) calling a sub program(Prog B). The program B (sub pgm) uses a file(File F1) to do its processing. Program A is calling program B dynamically. My doubt is should i open the file (in sub pgm) every time i call program B (sub pgm), or is it fine if i open the file once in Initial para in Program A (Main pgm).
Can anyone please help me in this.
Thanks in advance,
Sujesh. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
No, absolutely not. Open it ONCE in the Caller and access it in the Calling program. When you're done, close it in the Caller.
Try defining the file as EXTERNAL in both programs and see if this helps with your dilemma (requires VS/COBOL II and greater) as well as review the applicable IBM COBOL manual.
What have you tried?
Bill |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Not a programmer, so I could be way off of the mark here ......... but
Surely if you open the file every time, and my understanding is that the file is opened at the first record, your output from the program may not be very accurate. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
unless you issue a CANCEL Prog B
in Prog A
and
Prog B does not have the INITIAL clause in the program ID paragraph,
you OPEN the file in Program B on the first CALL from A
(yeah, need to save a switch in Progr B)
read the file in program B
and then a final call from A to B to close it.
or,
use the external clause
but you can do allllllll your file handling in program B without any problem. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
dbzTHEdinosauer wrote: |
unless you issue a CANCEL Prog B
in Prog A
and
Prog B does not have the INITIAL clause in the program ID paragraph,
you OPEN the file in Program B on the first CALL from A
(yeah, need to save a switch in Progr B)
read the file in program B
and then a final call from A to B to close it.
or,
use the external clause
but you can do allllllll your file handling in program B without any problem. |
If you want to have program A control all file handling you should implement a function code in your call parameters to B with (at least) 3 values:
One for open file, and possibly other initialisation
One for processing
One for closing file and other cleanup
You can also do with opening the file at first call, and set a switch to mark that the file has been opened. Closing the file can then be left to the operating system when program A ends, though that is generally not considered good practice. |
|
Back to top |
|
|
passion_sujesh
New User
Joined: 14 Mar 2008 Posts: 74 Location: India,Chennai
|
|
|
|
Thanks for ur reply,
I will use the method provided by 'Kjeld'. Can i use the same approach for both statically and dynamically called programs? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Can i use the same approach for both statically and dynamically called programs? |
What, exactly, do you mean by "statically and dynamically called"? The main difference between them is when does the program get loaded -- as part of the compile / linkage edit (bind) process, or when the calling program is executing. It certainly does not sound like this is what you mean, though. |
|
Back to top |
|
|
|