cobolgnucobol

gnucobol failing to open/create an indexed file


Following a course in COBOL, I'm trying to create an indexed file.

Many times the file reading chapter precedes the writing one, so I had no file to read, and an indexed file is not just a file.

Anyway, my following program is failing to fill data in the students file, although the students.dat and students.idx files are being created. .dat has zero size and .idx 12288 bytes. This might say an underlaying bdb or vbisam has been invoked.

Could you try to help me out?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
      FILE-CONTROL.
      SELECT optional STUDENT-DB ASSIGN TO 'students'
         ORGANIZATION IS INDEXED
         ACCESS IS RANDOM
         RECORD KEY IS DB-STUDENT-ID
         FILE STATUS IS FS.

DATA DIVISION.
   FILE SECTION.

   FD STUDENT-DB.
   01 DB-STUDENT.
      05 DB-STUDENT-ID PIC 9(5).
      05 DB-NAME PIC A(25).
      05 DB-CLASS PIC X(3).

   WORKING-STORAGE SECTION.
   01 FS PIC X(2).

PROCEDURE DIVISION.
   OPEN i-o STUDENT-DB.
   DISPLAY "FS open : "FS END-DISPLAY. *>30
   move 1000 TO DB-STUDENT-ID.
   move 'Tim' TO DB-NAME.
   move '10' TO DB-CLASS.
   DISPLAY 'DB-STUDENT-ID : 'DB-STUDENT-ID END-DISPLAY.
   DISPLAY 'DB-NAME : 'DB-NAME END-DISPLAY.
   DISPLAY 'DB-CLASS : 'DB-CLASS END-DISPLAY.
   DISPLAY 'DB-STUDENT : 'DB-STUDENT END-DISPLAY.
   WRITE DB-STUDENT END-WRITE.
   DISPLAY "FS write : "FS END-DISPLAY. *>48
   CLOSE STUDENT-DB.
   DISPLAY "FS close : "FS END-DISPLAY. *>42
STOP RUN.

This is my output:

FS open : 30
DB-STUDENT-ID : 01000
DB-NAME : Tim
DB-CLASS : 10
DB-STUDENT : 01000Tim                      10
FS write : 48
FS close : 42

and my compilation command:

cobc -d -free -Wall -Wextra -Wadditional -x index-create.cbl
$ cobcrun --info #gives on termux:
GnuCOBOL information
COB_MODULE_EXT           : so
dynamic loading          : system                          64bit-mode               : yes
BINARY-C-LONG            : 8 bytes
endianness               : little-endian
native EBCDIC            : no                              variable file format     : 0
sequential file handler  : built-in
indexed file handler     : VBISAM
mathematical library     : GMP, version 6.3.0
XML library              : libxml2, version 2.12.7
JSON library             : json-c, version 0.17.0
extended screen I/O      : ncursesw, version 6.4.20231001 (CHTYPE=32, WIDE=1)
mouse support            : unknown

a big thank in advance, alex


Solution

  • Finally a real working solution.

    With the encouragement and support of @SimonSobisch and other members of the gnucobol community, i was able to improve the configuration process to correctly employ libdb even in cross compiling cases.

    You may try this for yourself by downloading the artifacts off my repository "final test" workflow at github for your own android architecture. I could only test with aarch64.

    My hope, is that the termux packages maintainers will soon approve my patch to their main repository, by this pull request, which I encourage you to follow.