fileredhatcobolgnucobol

GnuCobol file not found


I am looking for a solution for the following problem. I run a very simple cobol program to read a file.

I use the following code :

 IDENTIFICATION DIVISION.      
   PROGRAM-ID. GADGETS.
   ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT Gadgetfile ASSIGN TO "STOCK.DAT"
           ORGANIZATION IS LINE SEQUENTIAL.
   DATA DIVISION.
   FILE SECTION.
   FD Gadgetfile.

The file stock.dat exist in the same directory of the program. I get the following error :

libcob: error: file does not exist (status = 35) for file Gadgetfile ('STOCK_DAT' => STOCK.DAT) If I use simple quote of double quote nothing change. This means that the program can't find the file. I use Gnucobol running on Redat 9.4 the same problem occur on fedora 40.

I think that I need to use some export of something related to DD ?

Help will be appreciated

Kind regards.


Solution

  • As you run on GNU/Linux, you will very likely run the program on a file system that is case-sensitive [1], therefore when you want to read "stock.dat", you also have to ASSIGN TO "stock.dat" (lower case).

    The COBOL runtime will search non-absolute filenames in the working directory of the program (not necessarily the place where the program resides). So you either want to start the program from that directory (cd /home/user/languages/cobol_lang && ./gadgets instead of /home/user/languages/cobol_lang/gadgets) or want to setup the file path (for GnuCOBOL's runtime library libcob: COB_FILE_PATH=/home/user/languages/cobol_lang /home/user/languages/cobol_lang/gadgets).
    As an alternative you can use file mapping for a single file, in GnuCOBOL that would be (no matter if you use upper- or lowercase in ASSIGN): DD_STOCK_DAT=/home/user/languages/cobol_lang/stock.dat /home/user/languages/cobol_lang/gadgets (you can also drop the DD_ prefix for the environment variable, if there's no environment variable with it, then libcob will check the name without it).


    And, as a different option: you can also ASSIGN TO stock-file-name and use MOVE "/home/user/languages/cobol_lang/gadgets/stock.dat" to that (or put it as initial VALUE into a variable with that name).


    [1] you may not have case-sensitive file systems on GNU/Linux (when mounting a FAT32 disk for example) and you may have a case-sensitive file system on Windows (even NTFS has that option, it is just uncommon)