Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Writing the same file in Main program and Subprogram

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
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    Post subject: Writing the same file in Main program and Subprogram
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7251

PostPosted: Tue Aug 30, 2011 2:59 pm    Post subject: Reply to: Writing the same file in Main program and Subprogr
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7251

PostPosted: Tue Aug 30, 2011 5:46 pm    Post subject: Reply to: Writing the same file in Main program and Subprogr
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Aug 30, 2011 5:49 pm    Post subject: Reply to: Writing the same file in Main program and Subprogr
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts I can not compile my program PL1 V3.R... Miguel Fernandez PL/I & Assembler 13 Tue Dec 06, 2016 8:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us