gnucobol failing to open/create an indexed file

  Kiến thức lập trình

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 berkeley 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

a big thank in advance,
alex

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT