unable to access files (SOLVED: blank spaced Dir name)

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)

Parents
  • 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.

     

     

  • 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.

  • 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?


  • 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


  • 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?

     

  • 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

     

  • I'm running the program from IDE only.

Reply Children
No Data