I am trying to find out a way to check whether a file is already opened in COBOL, so that I can open it if it is closed or close it if it is opened.
Thnx.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Check the
FILE STATUSand act accordingly.Try the following:
Add a
FILE-STATUSunder theFILE-CONTROL, for example:FILE-CONTROL. SELECT MYFILE ASSIGN MYDD ORGANIZATION SEQUENTIAL ACCESS SEQUENTIAL FILE STATUS MYFILE-STATUS.Declare a
FILE STATUSvariable inWORKING-STORAGEas a
PIC X(2)value, for example:01 MYFILE-STATUS PIC X(2). 88 MYFILE-ALREADY-OPEN VALUE '41'.Then in the
PROCEDURE DIVISIONissue anOPENfor yourfile. Immediately following that, test the value of
FILE STATUSas in:
OPEN MYFILE.... IF MYFILE-ALRADY-OPEN CLOSE MYFILE... END-IF IF MYFILE-STATUS <> '00' perform some sort of general error routine END-IFValues of
FILE STATUSwhere the first character is not a ‘9’, areCOBOL standard values so testing for ’41’ to detect an already open file
should work on all COBOL implementations. Beware when the first character is a ‘9’,
these are vendor specific file status codes. Check out the following link for
a good introduction to using COBOL
FILE STATUS: http://www.simotime.com/vsmfsk01.htm