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

calling program


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
krbabu

New User


Joined: 20 Feb 2004
Posts: 57

PostPosted: Fri Feb 27, 2004 10:03 am
Reply with quote

Hi ,
i have a doubt on calling and called program.

i have two programs P1 and P2. P1 is the called program and P2 is the calling program.I want to read a file in P1 and i want to write it on P2. My question is how to declare in COBOL and how write JCL for this?
Back to top
View user's profile Send private message
mcmillan

Site Admin


Joined: 18 May 2003
Posts: 1210
Location: India

PostPosted: Fri Feb 27, 2004 7:42 pm
Reply with quote

Hai,

Define your file as EXTERNAL and you can access that files from your P1 & P2, if they are nested programs.

See the sample given below:

Code:
The following table gives the names of the main program and subprograms
used in the example shown in Figure 59 and describes their functions.
 
┌────────────────────────────────────────────────────────────────────────┐
│ Figure 58. 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.                                         │
│                                                                        │
│                                                                        │
└────────────────────────────────────────────────────────────────────────┘



Quote:
The following items are
recommended to successfully process an EXTERNAL 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.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts DB2 Event passed to the Application P... DB2 1
Search our Forums:

Back to Top