View previous topic :: View next topic
|
Author |
Message |
vishalbshah
New User
Joined: 01 Dec 2006 Posts: 61 Location: Pune
|
|
|
|
Hi ,
I am having a error file, my Main program and subprograms are sharing this error file , I want to write errors from mainprogram as well as from subprogram.
I have coded same SELECT and FD statements in Main program as well as in Subprogram.
I have OPEN file in Mainprogram and written some records over there , when I am in to Subprogram I am just writing the record in file , I am getting SOC4 while executing WRITE Statement in Sub program as the FD record name is not having address in Sub program.
Can some one please, suggest how should I solve this issue? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
create a 3rd module,
which will contain the only FD for this file.
remove the FD from your mainmodule and sub-module.
only purpose is to write to error file.
create a copybook to use a linkage between your mainprogram and your subprogram,
input elements:- text to write
- function code
output elements:- return code
- error text (file status)
write module should maintain an internal flag to determine if file is open or not.
when write function-code - module should open the file if not open then write.
when close function-code - module should close file if open.
dynamically CALL this module from mainprogram and subprogram.
also, you will have a module that can be used by new modules. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
dbz's way is the way to go.
I don't feel a need not to do an open. The more "logic" there is, the easier it can be to spot errors through illogic use in the message module. Although in this case, it is all enormously simple. Important to check all the codes from file access and NOT call this module if you find a problem :-) |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
forgot to mention that the mainmodule should CALL this new module with
a CLOSE functioncode just before GOBACK (or STOP RUN if that is the level of your shop). |
|
Back to top |
|
|
vishalbshah
New User
Joined: 01 Dec 2006 Posts: 61 Location: Pune
|
|
|
|
dbzTHEdinosauer wrote: |
forgot to mention that the mainmodule should CALL this new module with
a CLOSE functioncode just before GOBACK (or STOP RUN if that is the level of your shop). |
Thanks!
Looks like writing a module is the only option or else I'll have to CLOSE and OPEN in EXTEND mode multiple times, which would be adding extra overhead. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The message writing is a technical thing, nothing to do with your business requirement, so no need to even think of complicating your code for the business function with some sort of weird "opening/closing, who knows when) sort of stuff.
Keep It Simple. Do it in the module. Called from main and sub-program. You then also have something, as dbz has already pointed out, that you can use in other programs, either directly or as a "clone". Makes the other programs less complex, more standard, better control/knowledge of where errors are written, etc. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
In VS/COBOL II version 3, EXTERNAL FILES were introduced. Documentation can be found in your applicable Programming Guide and/or Language Reference Guide for your applicable COBOL version/release.
Mr. Bill |
|
Back to top |
|
|
|