Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In cobol, I was trying to input records from an input file into a table/array: F

ID: 3813627 • Letter: I

Question

In cobol, I was trying to input records from an input file into a table/array:

FD input-file 01 Input-rec

02 city pic x(15).
02 mult-rate pic v999.
02 Filler pic x.

Working storage section

01 table-input

02 a-city-name pic x(15).

02 a-city-rate pic v999.

02 filler pic x.

01 city-table.

02 city-a occurs 22 times indexed by city-index

ascending key is city-name.

03 city-name pic x(15).

03 city-rate pic v999.

procedure division

0000-main-logic.

perform 1000-init.

perform 2000-table.

perform 3000-end.

1000-init.

open input input-file.

read input-file at end move "yes" to eof-flag.

2000-table.

read input-file into table-input at end move "yes" to eof-flag.

perform 2500-table.

2500-table.

set city-index to 1.

move a-city-name to city-name (city-index)

move a-city-rate to city-rate (city-index).

set city-index up by 1.

........

so i was having trouble understanding indexes and i ws working on my code above and cant get the input files to load into the table.

Explanation / Answer

IDENTIFICATION DIVISION.
     PROGRAM-ID. fileid1.

    ENVIRONMENT DIVISION.

     CONFIGURATION SECTION.
      SOURCE-COMPUTER. IBM-PC.
      OBJECT-COMPUTER. IBM-PC.

     INPUT-OUTPUT SECTION.
      FILE-CONTROL.
      
       SELECT file-write ASSIGN TO DISK
       ORGANIZATION IS LINE SEQUENTIAL.

    DATA DIVISION.
     FILE SECTION.
      FD file-write
       VALUE OF FILE-ID IS "filedemo.ctx".
       01 frec.
        02 frno PIC 99.
        02 fname1 PIC X(20).
        02 fm1 PIC 999.
        02 fm2 PIC 999.
        02 fm3 PIC 999.
        02 ftotal PIC 999.

     WORKING-STORAGE SECTION.
      01 rec.
        02 rno PIC 99.
        02 name1 PIC X(20).
        02 m1 PIC 999.
        02 m2 PIC 999.
        02 m3 PIC 999.
        02 total PIC 999.
      77 wish PIC X VALUE 'Y'.

     LINKAGE SECTION.
     REPORT SECTION.

    PROCEDURE DIVISION.
     begin.

        OPEN OUTPUT file-write.

        PERFORM UNTIL wish = 'N' OR 'n'
            DISPLAY "Enter Roll No :-> " WITH NO ADVANCING
            ACCEPT rno

            DISPLAY "Enter Name :-> " WITH NO ADVANCING
            ACCEPT name1

            DISPLAY "Enter Marks1 :-> " WITH NO ADVANCING
            ACCEPT m1

            DISPLAY "Enter Marks2 :-> " WITH NO ADVANCING
            ACCEPT m2

            DISPLAY "Enter Marks3 :-> " WITH NO ADVANCING
            ACCEPT m3

            COMPUTE total = m1 + m2 + m3

            MOVE rec TO frec
            WRITE frec

            DISPLAY "Would you like 2 continue??(Y/N):-> "
            ACCEPT wish

        END-PERFORM.

        CLOSE file-write.
        STOP RUN.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote