Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:25+00:00 2026-06-17T09:29:25+00:00

In the following program I perform a basic interaction with an indexed file. When

  • 0

In the following program I perform a basic interaction with an indexed file. When executed everything works as expected when I try to add a record, I even receive the success message. However when the code to read it – lees – tries to find the corresponding ID, it can’t find it. When I look at the size of the indexed file on my disk I can see it has a size of 0kb. What am I overlooking?

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. oef16_indexedfiles.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT indexfile ASSIGN TO "C:\Test\indexedfile.dat"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS id-number
ALTERNATE KEY IS fname WITH DUPLICATES
ALTERNATE KEY IS lname WITH DUPLICATES
ALTERNATE KEY IS city WITH DUPLICATES
ALTERNATE KEY IS hobby WITH DUPLICATES.

DATA DIVISION.
FILE SECTION.
FD indexfile.
01 persoon.
 02 id-number    PIC 9.
 02 name.
        03 fname        PIC A(25).
        03 lname        PIC A(30).
 02 city         PIC A(30).
 02 hobby        PIC X(40).

WORKING-STORAGE SECTION.
01 einde        PIC X.
01 msg          PIC X(50).
01 countno      PIC 9 VALUE 1.

PROCEDURE DIVISION.
PGM.
 PERFORM schrijf
 PERFORM lees
 STOP RUN.

   check.
    DISPLAY msg
    ACCEPT einde

   schrijf.
   MOVE "1 = stoppen, 0 = doorgaan" TO msg       
   PERFORM check
   OPEN I-O indexfile

   PERFORM UNTIL einde = 1
    MOVE countno TO id-number

    DISPLAY "Enter your first name:"
    ACCEPT fname

    DISPLAY "Enter your last name:"
    ACCEPT lname

    DISPLAY "Enter your city:"
    ACCEPT city

    DISPLAY "Enter your hobby:"
    ACCEPT hobby

    WRITE persoon
            INVALID KEY
                    DISPLAY "ERROR WRITING: " id-number
            NOT INVALID KEY
                    DISPLAY "ID " id-number " by " fname " is added"
    END-WRITE
    ADD 1 TO countno

    PERFORM check
   END-PERFORM
   CLOSE indexfile
   MOVE 0 TO einde

   lees.
    OPEN INPUT indexfile
    MOVE 1 TO id-number
    READ indexfile 
            INVALID KEY
                    DISPLAY "Invalid key: " id-number
            NOT INVALID KEY
                    DISPLAY id-number SPACE fname SPACE lname SPACE
                            city SPACE hobby
    END-READ

    CLOSE indexfile
    MOVE 0 TO einde
    ACCEPT einde
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:29:26+00:00Added an answer on June 17, 2026 at 9:29 am

    Try adding OPTIONAL to the SELECT phrase. Keep the OPEN I-O.

    SELECT OPTIONAL indexfile ASSIGN TO “indexedfile.dat”.

    OPTIONAL will allow opening a non-existent file in preparation for first write.

    Plus, follow Bill’s advice; get used to checking FILE-STATUS after any OPEN (or any access for that matter).

    After period terminating your paragraphs, and reformatting for FIXED form (a couple of display lines exceeded column 72), this code worked fine with OpenCOBOL once OPTIONAL was added. Before that it fails with

    libcob: File does not exist (STATUS = 35) File : ‘indexedfile.dat’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following assignment: Write a complete 8086 program to perform the calculator
The following program is a basic linked list divided in 3 classes. In the
I developed a C++ program which utilises an .exe file through the following code:
The following program expects user input in the mixed fraction format 'whole_numbernumerator/denominator' and assigns
The following program I'm creating will allow the user will input values to create
The following program, compiled with g++ 4.6, yields the error request for member ‘y’
The following program: import multiprocessing,operator f = operator.itemgetter(0) # def f(*a): return operator.itemgetter(0)(*a) if
the following program force quit and crashes, I don't understand why, import android.app.Activity; import
Consider following program: static void Main (string[] args) { int i; uint ui; i
In following program . I have one doubt. I have declared one global variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.