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

  • Home
  • SEARCH
  • 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 4251840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:42:56+00:00 2026-05-21T04:42:56+00:00

A Cobol program reads a record from a first flat file and compares it

  • 0

A Cobol program reads a record from a first flat file and compares it to the first record on a second flat file. However, because the first record from the first flat file does not match any records on the second flat file, the Cobol program goes into an infinite loop. How do I fix it?

  • 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-05-21T04:42:57+00:00Added an answer on May 21, 2026 at 4:42 am

    Smells like a logic error somewhere in the program. Hard to say
    what that might be. But I do have a few ideas…

    Possible causes of an infinite loop:

    • Failure to check end-of-file conditions
    • Not reacting to the end-of-file properly
    • Testing for end-of-file but assuming all other conditions are ‘successful’ reads

    End of file is sometimes determined by testing the File Status after each
    I/O operation. File Status is an optional 2 character data item associated with the file being
    read/written. It is specified
    in the FILE-CONTROL paragraph of your program. For example:

       SELECT file-name ASSIGN TO dd-name FILE STATUS fstatus
    

    where: file-name is the name you refer to in OPEN/READ/WRITE/CLOSE statements. dd-name
    is the external file name (the DDNAME from your JCL). fstatus is a two character data item declared
    under WORKING-STORAGE.

    The File Status is set on every file I/O operation. For example:

        READ file-name
    

    sets the fstatus to end-of-file if there were no more records to read. Note that the File Status
    variable is not actually referenced on the READ, but it is set.

    File Status values are two characters and are defined in the ISO COBOL standard, they should
    be the same for all COBOL implementations. The exception being File Status values where the first
    character is a ‘9’, these are implementation dependant. Here is a link to the IBM Enterprise
    COBOL File Status values

    The value for end-of-file is: ’10’ – which should be the same for all COBOL implementations.

    It is my guess that your program has a File Status for each of the input files, but is not checking it or reacting to it
    appropriately. For example, your program may only check for end-of-file but not other conditions:

       IF fstatus = '10'
          PERFORM END-OF-FILE-LOGIC
       ELSE
          PERFORM NORMAL-LOGIC
       END-IF
    

    The problem with this approach is that it treats normal returns (fstatus = ’00’) and all non-end-of-file error
    conditions as if the READ was successful. Better to have something like:

       EVALUATE fstatus
           WHEN '10'
               PERFORM END-OF-FILE-LOGIC
           WHEN '00'
               PERFORM NORMAL-LOGIC
           WHEN OTHER
               PERFORM UNEXPECTED-ERROR
       END-EVALUATE
    

    There is an imperative form of the READ statement that specifies what to do when the end of file
    is reached. It goes something like:

       READ file-name AT END PERFORM END-OF-FILE-LOGIC END-READ
    

    Again, if a File Status was specified in the FILE-CONTROL section for file-name and a non-end-of-file
    error occurred, your program would attempt to continue with ‘normal’ logic – exactly the wrong thing to be
    doing.

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

Sidebar

Related Questions

I'm building my first Python program :) However, I installed Python 3.2 instead of
I have the following code snippet in one of my COBOL program. IF FIRST
I need to make a program that reads a file, and puts all of
Is it possible to make my cobol program to executable file or having .bat?
I ran into a strange statement when working on a COBOL program from $WORK.
I have an existing MF COBOL 4.0 program with years of data in a
Is it possible to abend your job intentionally through COBOL program. suppose I have
I'm using CICS in Cobol program and I've noticed that sometimes data are written
I'm currently writing a program that needs to compare each file in an ArrayList
If I have 1 COBOL DB2 program which is calling 2 other COBOL DB2

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.