I'm using Visual Studio 2019 Visual Cobol and I have problems accessing sequential files. When I try in the program to open a Sequential/line sequential files, with variable record length, the data accessed is not from the opened file but of another file created in previous runs. They are like ghost files. So there is no way I can access existing sequential files. Also, I created sequential files under VS, using internal data and it works fine, but then these files cannot be accessed (file not found) by another external program.
Jan 26, 2021: PROBLEM SOLVED thanks to the help of this Community's users.
Origin: Use of Spaced Directory names(Windows platform).
Two solutions:
1- Do not use blank spaced Directory names, e.g: NO: "D:\\File1 part1\\......\\filename". (blank spaced)
YES: "D:\\File1part1\\......\\filename". (No blank spaced)
2- USE blank spaced Directory names, but add extra single quotes:
YES: ' "D:\\File1 part1\\......\\filename" '. (blank spaced Dir and extra single
quotes)
#Directorynames#variablerecord#sequential#externalfilesOpen Input —> for read
open output —> for create
open i-0 —> for read , Write, delete
open extend —> for attach at end new data
I'm using Visual Studio 2019 Visual Cobol and I have problems accessing sequential files. When I try in the program to open a Sequential/line sequential files, with variable record length, the data accessed is not from the opened file but of another file created in previous runs. They are like ghost files. So there is no way I can access existing sequential files. Also, I created sequential files under VS, using internal data and it works fine, but then these files cannot be accessed (file not found) by another external program.
Jan 26, 2021: PROBLEM SOLVED thanks to the help of this Community's users.
Origin: Use of Spaced Directory names(Windows platform).
Two solutions:
1- Do not use blank spaced Directory names, e.g: NO: "D:\\File1 part1\\......\\filename". (blank spaced)
YES: "D:\\File1part1\\......\\filename". (No blank spaced)
2- USE blank spaced Directory names, but add extra single quotes:
YES: ' "D:\\File1 part1\\......\\filename" '. (blank spaced Dir and extra single
quotes)
#Directorynames#variablerecord#sequential#externalfilesHow you define the file depends on what type of file you are opening. If the file is created with a text editor and has line terminator characters like X"0A" or X"0D0A" then you need to define it as line sequential in the select statement.
select line-seq-file assign to "filename.txt"
organization is line sequential.
fd line-seq-file.
01 line-seq-record pic x(??).
open input line-seq-file
perform until exit
read line-seq-file
at end
exit perform
not at end
perform 100-process-file
end-read
end-perform
Is this how your file is defined?
How you define the file depends on what type of file you are opening. If the file is created with a text editor and has line terminator characters like X"0A" or X"0D0A" then you need to define it as line sequential in the select statement.
select line-seq-file assign to "filename.txt"
organization is line sequential.
fd line-seq-file.
01 line-seq-record pic x(??).
open input line-seq-file
perform until exit
read line-seq-file
at end
exit perform
not at end
perform 100-process-file
end-read
end-perform
Is this how your file is defined?
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
FD TEST-FILE3 RECORD varying from 1 to 200 depending on WS-CURRENT-RECL.
01 TEST-FILE-REC.
02 TERM-REC1 PIC X(100).
02 TERM-REC2 PIC X(100).
********************************
OPEN INPUT TEST-FILE3.
PERFORM 40 times
READ TEST-FILE3
AT END DISPLAY "****.END OF TESTFILE1" GOBACK
NOT AT END
DISPLAY TEST-FILE-REC.(1:WS-CURRENT-RECL)
END-READ
END-PERFORM.
******
That is my code, but the problem is that the content of the file displayed is not that of the opened file, but of another file I previously created with the VS COBOL program using some test data. I changed the
Input file to another file, with the same result. No matter what input file I use, the displayed data is the same!! Additionally, I created with another program a Seq,, Var Rec. file and used it as Input File and the result is the same: same data content displayed. I am using: W10, VS COBOL, Visual studio 2019, the input file is a file created using Notepad (line seq., var record). The very same code runs perfectly under OpenCobolIDE. Really I do no understand it all. Regards.
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
FD TEST-FILE3 RECORD varying from 1 to 200 depending on WS-CURRENT-RECL.
01 TEST-FILE-REC.
02 TERM-REC1 PIC X(100).
02 TERM-REC2 PIC X(100).
********************************
OPEN INPUT TEST-FILE3.
PERFORM 40 times
READ TEST-FILE3
AT END DISPLAY "****.END OF TESTFILE1" GOBACK
NOT AT END
DISPLAY TEST-FILE-REC.(1:WS-CURRENT-RECL)
END-READ
END-PERFORM.
******
That is my code, but the problem is that the content of the file displayed is not that of the opened file, but of another file I previously created with the VS COBOL program using some test data. I changed the
Input file to another file, with the same result. No matter what input file I use, the displayed data is the same!! Additionally, I created with another program a Seq,, Var Rec. file and used it as Input File and the result is the same: same data content displayed. I am using: W10, VS COBOL, Visual studio 2019, the input file is a file created using Notepad (line seq., var record). The very same code runs perfectly under OpenCobolIDE. Really I do no understand it all. Regards.
Is TESTFILE-DSNAME a variable that you have in your program?
The physical file name will be whatever this variable contains at the time the file is opened.
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
FD TEST-FILE3 RECORD varying from 1 to 200 depending on WS-CURRENT-RECL.
01 TEST-FILE-REC.
02 TERM-REC1 PIC X(100).
02 TERM-REC2 PIC X(100).
********************************
OPEN INPUT TEST-FILE3.
PERFORM 40 times
READ TEST-FILE3
AT END DISPLAY "****.END OF TESTFILE1" GOBACK
NOT AT END
DISPLAY TEST-FILE-REC.(1:WS-CURRENT-RECL)
END-READ
END-PERFORM.
******
That is my code, but the problem is that the content of the file displayed is not that of the opened file, but of another file I previously created with the VS COBOL program using some test data. I changed the
Input file to another file, with the same result. No matter what input file I use, the displayed data is the same!! Additionally, I created with another program a Seq,, Var Rec. file and used it as Input File and the result is the same: same data content displayed. I am using: W10, VS COBOL, Visual studio 2019, the input file is a file created using Notepad (line seq., var record). The very same code runs perfectly under OpenCobolIDE. Really I do no understand it all. Regards.
Try adding a display of File1-Status after the file open and the read to see if you get a zero return code.
Alsop are you running this in the IDE or from a command line?
Is TESTFILE-DSNAME a variable that you have in your program?
The physical file name will be whatever this variable contains at the time the file is opened.
If it's not a variable then that will be the file name from the current directory or where the program is being run from
Is TESTFILE-DSNAME a variable that you have in your program?
The physical file name will be whatever this variable contains at the time the file is opened.
Yes, TESTFILE-DSNAMEis a variablble with the full path address of the file, which is:
"D:\\PROJCOBOL\\WORKAREA\\NEW PROJ 2020\\TESTDATAJAN2021\\
- "TERMNOTEPADHAND.TXT".
Today I made another test:
1- Created a new Solution (Cobol, native)
2- I copied into the new program the code for testing
3- Result: File Status ok, File's path(Dsname) ok, but the displayed data is still the "ghost one"; not
from the Input file.
As I am new at this Forum, can I attach photos of my program and results?
If it's not a variable then that will be the file name from the current directory or where the program is being run from
Just to give the full info., if it helps:
The PROGRAM's CODING:
***************************
FILE-CONTROL.
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
DATA DIVISION.
FILE SECTION.
FD TEST-FILE3 RECORD VARYING FROM 1 TO 500
DEPENDING ON WS-CURRENT-RECL.
01 ZAP005D1-REC
02 TERM-REC PIC X(458).
02 SECUENCIA PIC 99.
01 RECORD2.
02 FILLER PIC X(20)
working-storage section.
**** FILES' FULL PATH*********************************
01 TESTFILE-DSNAME PIC X(80) VALUE
"D:\\PROJCOBOL\\WORKAREA\\NEW PROJ 2020\\TESTDATAJAN2021\\
- "TERMNOTEPADHAND.TXT".
****
77 WS-RECLEN PIC 9(3) COMP VALUE 256.
77 FILENOME2 PIC X(22) VALUE "D:\\V005313572BANK1.TXT".
77 STATUS3 PIC 9(2) VALUE 0.
77 WS-CURRENT-RECL PIC 9(4) COMP VALUE 0.
77 WS-DATAINF-RECL PIC 9(4) COMP VALUE 0.
01 FILE1-STATUS.
05 FILE1A-STATUS-L PIC 9.
05 FILE1B-STATUS-R PIC 9.
77 FILE2-STATUS PIC XX.
77 FILE3-STATUS PIC XX.
PROCEDURE DIVISION.
DISPLAY "XXXX..INPUT FILE FULL PATH.->" TESTFILE-DSNAME.
OPEN INPUT TEST-FILE3.
IF FILE1-STATUS NOT = ZERO
DISPLAY "..ERROR OPENING.FILE STATUS->" FILE1-STATUS
GOBACK
END-IF
DISPLAY " FILE STATUS AFTER OPEN->" FILE1-STATUS.
LEA1.
PERFORM 5 TIMES
READ TEST-FILE3
AT END DISPLAY "..END OF TESTFILE1"
STOP 999
GOBACK
NOT AT END
DISPLAY "/RECORD->" ZAP005D1-REC(1:WS-CURRENT-RECL)
FILE1-STATUSccc "/RECL->" cccWS-CURRENT-RECL
"/FS AFTER READ->"
END-READ
STOP 666
GOBACK
END-PERFORM.
CLOSE TEST-FILE3.
STOP 7767
GOBACK.
end program FILETEST1.
******************************************************************************
I am attaching Input File Data and Data Displayed form the program:
Regards
Try adding a display of File1-Status after the file open and the read to see if you get a zero return code.
Alsop are you running this in the IDE or from a command line?
I'm running the program from IDE only.
Open Input —> for read
open output —> for create
open i-0 —> for read , Write, delete
open extend —> for attach at end new data
See my recent reply. Regards.
See my recent reply. Regards.
From the screenshot Notepad appears to be open a file without the .txt extension and the program is opening a file with the .txt extension.
Do you perhaps have 2 versions of this file in your folder?
From the screenshot Notepad appears to be open a file without the .txt extension and the program is opening a file with the .txt extension.
Do you perhaps have 2 versions of this file in your folder?
Notepad doesn't show the file type, just the filename. Regards.
From the screenshot Notepad appears to be open a file without the .txt extension and the program is opening a file with the .txt extension.
Do you perhaps have 2 versions of this file in your folder?
Forgot to add that there are no duplicate files, also I have tried with different files form different directories. Regards.
Yes, TESTFILE-DSNAMEis a variablble with the full path address of the file, which is:
"D:\\PROJCOBOL\\WORKAREA\\NEW PROJ 2020\\TESTDATAJAN2021\\
- "TERMNOTEPADHAND.TXT".
Today I made another test:
1- Created a new Solution (Cobol, native)
2- I copied into the new program the code for testing
3- Result: File Status ok, File's path(Dsname) ok, but the displayed data is still the "ghost one"; not
from the Input file.
As I am new at this Forum, can I attach photos of my program and results?
See if this file with the "ghost data" exists anywhere else on your system.
See if this file with the "ghost data" exists anywhere else on your system.
No. I did an extensive search through all the directories but couldn't
find it.
As I mentioned before, the displayed data is of a file I created from a VS
Cobol program.No matter Input file I use, the same data is displayed/get.
Regards.
No. I did an extensive search through all the directories but couldn't
find it.
As I mentioned before, the displayed data is of a file I created from a VS
Cobol program.No matter Input file I use, the same data is displayed/get.
Regards.
Sorry was behind in the post. So in looking at the full program, that program did not produce the output you attached. The program you attached does a stop 666 after each read and then does a goback so at most it will read and display one record. Perhaps upload the actual COBOL code to and the actual datafile to this thread.
The other things, if at all possible can you move the datafile to a directory structure without spaces in the name. change your code and see if that helps.
Last question, was the input file created by another program or did you manually create it?
No. I did an extensive search through all the directories but couldn't
find it.
As I mentioned before, the displayed data is of a file I created from a VS
Cobol program.No matter Input file I use, the same data is displayed/get.
Regards.
99% sure It's the spaces in the directory name that are killing you. See if there isn't a file called NEW in the directory D:\\PROJCOBOL\\WORKAREA\\ and if it doesn't match the displays
Sorry was behind in the post. So in looking at the full program, that program did not produce the output you attached. The program you attached does a stop 666 after each read and then does a goback so at most it will read and display one record. Perhaps upload the actual COBOL code to and the actual datafile to this thread.
The other things, if at all possible can you move the datafile to a directory structure without spaces in the name. change your code and see if that helps.
Last question, was the input file created by another program or did you manually create it?
Hi to all:
My problem was SOLVED, as suggested, by NOT using multi-word DIR names (e.g
TESTFILE and not TEST FILE). I am attaching the image of the failed Run
display (with Ghost data) using blank spaced directory name
("D:\\PROJCOBOL\\WORKAREA\\*NEW PROJ 2020*\\TERMNOTEPADHAND.TXT"), and the
image of the Not-failed run display using non-spaced Dir name (
("D:\\PROJCOBOL\\WORKAREA\\*NEWPROJ2020*\\TERMNOTEPADHAND.TXT"), In my previous
sample program, I was reading just 1 record and using the STOP xxxx command
in order to watch the data displayed on the screen.
Thanks to you all for the help. Regards.
Note: The first line of the Displays shows the full access path of the file.
99% sure It's the spaces in the directory name that are killing you. See if there isn't a file called NEW in the directory D:\\PROJCOBOL\\WORKAREA\\ and if it doesn't match the displays
SteveW2:
As I mention in my last Post, you were right regarding spaced Dir names: the problem was fixed not using multi-word Dir names. Here attach copy of my Cobol test program, the file used for testing, and the images of the output displays with blank-spaced and non-blank spaced Dir names. Still Unresolved the origin of the Ghost file data. I used Comment line to switch file's path.
REGARDS
-------
IDENTIFICATION DIVISION.
PROGRAM-ID. FILETEST1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
DATA DIVISION.
FILE SECTION.
FD TEST-FILE3 RECORD VARYING FROM 1 TO 500
DEPENDING ON WS-CURRENT-RECL.
01 ZAP005D1-REC.
02 TERM1-REC PIC X(458).
02 TERM2-REC PIC 9(2).
WORKING-STORAGE SECTION.
77 WS-CURRENT-RECL PIC 9(4) COMP VALUE 0.
01 FILE1-STATUS.
05 FILE1A-STATUS PIC X.
05 FILE1B-STATUS PIC X.
**** FILE' FULL PATH *********************************
01 TESTFILE-DSNAME PIC X(80) VALUE
***** "D:\\PROJCOBOL\\WORKAREA\\NEW PROJ 2020\\TERMNOTEPADHAND.TXT". *>FAIL
"D:\\PROJCOBOL\\WORKAREA\\NEWPROJ2020\\TERMNOTEPADHAND.TXT". *> OK
PROCEDURE DIVISION.
DISPLAY " "
DISPLAY "***INPUT FILE FULL PATH.->" TESTFILE-DSNAME
OPEN INPUT TEST-FILE3
DISPLAY "OPENING.FILE STATUS->" FILE1A-STATUS "/" FILE1B-STATUS
IF FILE1-STATUS NOT = ZERO
DISPLAY "..ERROR OPENING.FILE STATUS->" FILE1-STATUS
GOBACK
END-IF
****
PERFORM 5 TIMES
READ TEST-FILE3
AT END DISPLAY "..END OF TESTFILE1"
STOP 999
GOBACK
NOT AT END
DISPLAY "/RECORD->" ZAP005D1-REC(1:WS-CURRENT-RECL)
"/RECL->" WS-CURRENT-RECL "/FS AFTER READ->" FILE1-STATUS
END-READ
END-PERFORM
CLOSE TEST-FILE3
STOP 888
GOBACK.
END PROGRAM FILETEST1.
SteveW2:
As I mention in my last Post, you were right regarding spaced Dir names: the problem was fixed not using multi-word Dir names. Here attach copy of my Cobol test program, the file used for testing, and the images of the output displays with blank-spaced and non-blank spaced Dir names. Still Unresolved the origin of the Ghost file data. I used Comment line to switch file's path.
REGARDS
-------
IDENTIFICATION DIVISION.
PROGRAM-ID. FILETEST1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TEST-FILE3 ASSIGN TO TESTFILE-DSNAME
ORGANIZATION LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL
FILE STATUS IS FILE1-STATUS.
DATA DIVISION.
FILE SECTION.
FD TEST-FILE3 RECORD VARYING FROM 1 TO 500
DEPENDING ON WS-CURRENT-RECL.
01 ZAP005D1-REC.
02 TERM1-REC PIC X(458).
02 TERM2-REC PIC 9(2).
WORKING-STORAGE SECTION.
77 WS-CURRENT-RECL PIC 9(4) COMP VALUE 0.
01 FILE1-STATUS.
05 FILE1A-STATUS PIC X.
05 FILE1B-STATUS PIC X.
**** FILE' FULL PATH *********************************
01 TESTFILE-DSNAME PIC X(80) VALUE
***** "D:\\PROJCOBOL\\WORKAREA\\NEW PROJ 2020\\TERMNOTEPADHAND.TXT". *>FAIL
"D:\\PROJCOBOL\\WORKAREA\\NEWPROJ2020\\TERMNOTEPADHAND.TXT". *> OK
PROCEDURE DIVISION.
DISPLAY " "
DISPLAY "***INPUT FILE FULL PATH.->" TESTFILE-DSNAME
OPEN INPUT TEST-FILE3
DISPLAY "OPENING.FILE STATUS->" FILE1A-STATUS "/" FILE1B-STATUS
IF FILE1-STATUS NOT = ZERO
DISPLAY "..ERROR OPENING.FILE STATUS->" FILE1-STATUS
GOBACK
END-IF
****
PERFORM 5 TIMES
READ TEST-FILE3
AT END DISPLAY "..END OF TESTFILE1"
STOP 999
GOBACK
NOT AT END
DISPLAY "/RECORD->" ZAP005D1-REC(1:WS-CURRENT-RECL)
"/RECL->" WS-CURRENT-RECL "/FS AFTER READ->" FILE1-STATUS
END-READ
END-PERFORM
CLOSE TEST-FILE3
STOP 888
GOBACK.
END PROGRAM FILETEST1.
How was the input file originally created? Was they a program that wrote it out? In this directory D:\\PROJCOBOL\\WORKAREA, is there a file called NEW? If so when you edit it, does it match the ghost data? I'm guessing it does.
How was the input file originally created? Was they a program that wrote it out? In this directory D:\\PROJCOBOL\\WORKAREA, is there a file called NEW? If so when you edit it, does it match the ghost data? I'm guessing it does.
SteveW2:
Yes, I found the Workarea/NEW file and it corresponds to the "ghost" data; fine, we finally know its origin. I think it's a file (of Var len) I created from a Cob program where I didn't append the file type. Well now remains: what's the link to my program? Anyway, it's a good help of yours, One comment: How to close the case with the finding?
SteveW2:
Yes, I found the Workarea/NEW file and it corresponds to the "ghost" data; fine, we finally know its origin. I think it's a file (of Var len) I created from a Cob program where I didn't append the file type. Well now remains: what's the link to my program? Anyway, it's a good help of yours, One comment: How to close the case with the finding?
The link to your program was the variable with the spaces in the file name. Everything in that variable after NEW was ignored which is how you got to that file
The link to your program was the variable with the spaces in the file name. Everything in that variable after NEW was ignored which is how you got to that file
It is possible to use spacey file-names. You just need to enclose the entire file-name within quotes itself.
Example:
identification division.
program-id. Program1.
select test-file assign to my-file-name
organization is line sequential
file status is file-status.
data division.
fd test-file.
01 test-rec pic x(20).
working-storage section.
01 file-status pic x(2) value spaces.
01 my-file-name pic x(100)
value '"d:\\tests\\my spacey filename.txt"'.
procedure division.
open output test-file
display file-status
move all "A" to test-rec
write test-rec
display file-status
close test-file
open input test-file
display file-status
read test-file
at end
display "at end"
not at end
display test-rec
end-read
close test-file
goback.
It is possible to use spacey file-names. You just need to enclose the entire file-name within quotes itself.
Example:
identification division.
program-id. Program1.
select test-file assign to my-file-name
organization is line sequential
file status is file-status.
data division.
fd test-file.
01 test-rec pic x(20).
working-storage section.
01 file-status pic x(2) value spaces.
01 my-file-name pic x(100)
value '"d:\\tests\\my spacey filename.txt"'.
procedure division.
open output test-file
display file-status
move all "A" to test-rec
write test-rec
display file-status
close test-file
open input test-file
display file-status
read test-file
at end
display "at end"
not at end
display test-rec
end-read
close test-file
goback.
Chris:
I've tested your suggested coding -- adding extra single quotes to double quotes when using
spaced-word filename (' "TEST FILE" '),-- and it WORKED. But, is it a standard format compatible across various Cobol versions? Regards.