mcmillan
Site Admin

Joined: 18 May 2003 Posts: 1211 Location: India
|
|
|
|
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. |
|
|