Skip to main content

Accessing a file in more than one program

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

Opening a file in a "MAIN" program and reading its records in another program "SUB" which is called by "MAIN" results in a file status=47 means: "A READ or START operation has been tried on a file not opened INPUT or I-O."

Must the file be opened in each program?

Resolution:

NO! Please specify in the FD the EXTERNAL clause and add this FD to the SELECT in each program which uses the file.

BTW: The variables of the FD are external variables and have the same value in each program where specified.

The core of the attached 4 files:

------------------------------------

       program-id. Sub.

       copy SEL.

       copy FD.

       display "read: " REC(1:20)

       read MyFile.

       display "read: " REC(1:20)

------------------------------------

       program-id. Main.

       copy SEL.

       copy FD.

       open input MyFile

       read MyFile  display "read: " REC(1:20)

       call "SUB"

       read MyFile  display "read: " REC(1:20)

       close MyFile.

------------------------------------

       select MyFile assign "TheFile.DAT".

------------------------------------

       FD MyFile external.

       01 rec pic x(80).

Attachments:

ExternalFiles.zip

Old KB# 4540

#COBOL
#AcuCobol
#RMCOBOL
#netexpress
#ServerExpress