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

SHARING OF FILES BETWEEN PROGRAMS


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

New User


Joined: 09 Nov 2003
Posts: 4
Location: India

PostPosted: Sun Nov 09, 2003 3:20 pm
Reply with quote

Hello Everybody ,
Suppose there are 2 programs PROG A AND PROG B . A CALLS B .Is it possible a file "MYFILE" IS OPENED IN A AND SOME DATA IS WRITTEN INTO IT IN B .Is there any way of sharing of files between the programs just like there is a EXTERNAL to share working storage variables among the programs .

Thanks ,

Yashvanth .
Back to top
View user's profile Send private message
mcmillan

Site Admin


Joined: 18 May 2003
Posts: 1210
Location: India

PostPosted: Wed Feb 18, 2004 5:38 pm
Reply with quote

Dear,

Yes you can access a same file from two programs y defining as external. For that the file must be sharable. I hope this snapshot will help you.


Code:
 Input/Output Using EXTERNAL Files
 
Using the EXTERNAL clause for files allows separately compiled programs
within the run unit to have access to common files.  The example on page

 shows some of the advantages of using EXTERNAL files:
 
   The main program can reference the record area of the file, even
    though the main program does not contain any I/O statements.
 
   Each subprogram can control a single I/O function, such as OPEN or
    READ.
 
   Each program has access to the file.
 
 
   The file-name in the SELECT clause of all the programs accessing the
    file must match.
 
   The assignment-name in the ASSIGN clause of all the programs accessing
    the file must match.
 
   The data-name in the FILE STATUS clause of all the programs that will
    check the file status code must match.
 
   EXTERNAL must be coded in the file's FD entry in all the programs
    accessing the file.
 
   For all programs that want to check the same file status field, the
    EXTERNAL clause must be coded on the level-01 data definition for the
    file status field in each program.
 
 
The following table gives the names of the main program and subprograms
used in the example shown in Figure 59 and describes their functions.
 
+------------------------------------------------------------------------+
?   Program Names for Input/Output Using EXTERNAL Files         ?
+------------------------------------------------------------------------?
? Name         ? Function                                                ?
+--------------+---------------------------------------------------------?
? ef1          ? This is the main program. It calls all the subprograms, ?
?              ? and then verifies the contents of a record area.        ?
+--------------+---------------------------------------------------------?
? ef1openo     ? This program opens the external file for output and     ?
?              ? checks the File Status Code.                            ?
+--------------+---------------------------------------------------------?
? ef1write     ? This program writes a record to the external file and   ?
?              ? checks the File Status Code.                            ?
+--------------+---------------------------------------------------------?
? ef1openi     ? This program opens the external file for input and      ?
?              ? checks the File Status Code.                            ?
+--------------+---------------------------------------------------------?
? ef1read      ? This program reads a record from the external file and  ?
?              ? checks the File Status Code.                            ?
+--------------+---------------------------------------------------------?
? ef1close     ? This program closes the external file and checks the    ?
?              ? File Status Code.                                       ?
+------------------------------------------------------------------------+
 
Additionally, COPY statements ensure that each subprogram contains an
identical description of the file.
 
Each program in the example declares a data item with the EXTERNAL clause
in its Working-Storage Section.  This item is used to check file status
codes, and is also placed using the COPY statement.
 
Each program uses three Copy Library members:
 
   The first is named efselect and is placed in the File-Control
    paragraph.
 
             Select ef1
                Assign To ef1
                File Status Is efs1
                Organization Is Sequential.
 
   The second is named effile and is placed in the File Section.
 
             Fd ef1 Is External
                       Record Contains 80 Characters
                       Recording Mode F.
             01  ef-record-1.
                 02  ef-item-1   Pic X(80).
 
   The third is named efwrkstg and is placed in the Working-Storage
    Section.
 
             01  efs1            Pic 99 External.
 
 
+------------------------------------------------------------------------+
?                                                                        ?
?                                                                        ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1.                                                      ?
?         *                                                              ?
?         * This is the main program that controls the external file     ?
?         * processing.                                                  ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Call "ef1openo"                                           ?
?              Call "ef1write"                                           ?
?              Call "ef1close"                                           ?
?              Call "ef1openi"                                           ?
?              Call "ef1read"                                            ?
?              If ef-record-1 = "First record" Then                      ?
?                Display "First record correct"                          ?
?              Else                                                      ?
?                Display "First record incorrect"                        ?
?                Display "Expected: " "First record"                     ?
?                Display "Found   : " ef-record-1                        ?
?              End-If                                                    ?
?              Call "ef1close"                                           ?
?              Goback.                                                   ?
?          End Program ef1.                                              ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1openo.                                                 ?
?         *                                                              ?
?         * This program opens the external file for output.             ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Open Output ef1                                           ?
?              If efs1 Not = 0                                           ?
?                Display "file status " efs1 " on open output"           ?
?                Stop Run                                                ?
?              End-If                                                    ?
?              Goback.                                                   ?
?          End Program ef1openo.                                         ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1write.                                                 ?
?         *                                                              ?
?         * This program writes a record to the external file.           ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Move "First record" to ef-record-1                        ?
?              Write ef-record-1                                         ?
?              If efs1 Not = 0                                           ?
?                Display "file status " efs1 " on write"                 ?
?                Stop Run                                                ?
?              End-If                                                    ?
?              Goback.                                                   ?
?          End Program ef1write.                                         ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1openi.                                                 ?
?         *                                                              ?
?         * This program opens the external file for input.              ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Open Input ef1                                            ?
?              If efs1 Not = 0                                           ?
?                Display "file status " efs1 " on open input"            ?
?                Stop Run                                                ?
?              End-If                                                    ?
?              Goback.                                                   ?
?          End Program ef1openi.                                         ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1read.                                                  ?
?         *                                                              ?
?         * This program reads a record from the external file.          ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Read ef1                                                  ?
?              If efs1 Not = 0                                           ?
?                Display "file status " efs1 " on read"                  ?
?                Stop Run                                                ?
?              End-If                                                    ?
?              Goback.                                                   ?
?          End Program ef1read.                                          ?
?          Identification Division.                                      ?
?          Program-Id.                                                   ?
?              ef1close.                                                 ?
?         *                                                              ?
?         * This program closes the external file.                       ?
?         *                                                              ?
?          Environment Division.                                         ?
?          Input-Output Section.                                         ?
?          File-Control.                                                 ?
?              Copy efselect.                                            ?
?          Data Division.                                                ?
?          File Section.                                                 ?
?              Copy effile.                                              ?
?          Working-Storage Section.                                      ?
?              Copy efwrkstg.                                            ?
?          Procedure Division.                                           ?
?              Close ef1                                                 ?
?              If efs1 Not = 0                                           ?
?                Display "file status " efs1 " on close"                 ?
?                Stop Run                                                ?
?              End-If                                                    ?
?              Goback.                                                   ?
?          End Program ef1close.                                         ?
?                                                                        ?
?                                                                        ?
+------------------------------------------------------------------------+
             Input/Output Using EXTERNAL Files
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 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
Search our Forums:

Back to Top