IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Writing the same file in Main program and Subprogram


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Tue Aug 30, 2011 1:02 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 30, 2011 2:23 pm
Reply with quote

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
    • WRITE
    • CLOSE


output elements:
  • return code
    • ok
    • not ok
  • 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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 30, 2011 2:59 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 30, 2011 5:33 pm
Reply with quote

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
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Tue Aug 30, 2011 5:36 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 30, 2011 5:46 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 30, 2011 5:49 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Using API Gateway from CICS program CICS 0
Search our Forums:

Back to Top