       IDENTIFICATION DIVISION.
       PROGRAM-ID.  FILTST.
      *            (FILE SYSTEM TEST)
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.  RMCOBOL.
       OBJECT-COMPUTER.  RMCOBOL.
      *
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT SEQ-FILE ASSIGN TO INPUT-OUTPUT, "SEQFL".
           SELECT REL-FILE ASSIGN TO RANDOM, "RELFL"
               ORGANIZATION IS RELATIVE,
               ACCESS MODE IS RANDOM,
               RELATIVE KEY IS REL-KEY.
           SELECT INX-FILE ASSIGN TO RANDOM, "INXFL"
               ORGANIZATION IS INDEXED,
               ACCESS MODE IS DYNAMIC,
               RECORD KEY IS INX-KEY,
                   ALTERNATE RECORD KEY IS ALT-KEY.
      *
       DATA DIVISION.
       FILE SECTION.
       FD  SEQ-FILE
               BLOCK CONTAINS 8 RECORDS
               LABEL RECORDS ARE STANDARD
               DATA RECORD IS SEQ-RECORD.
       01  SEQ-RECORD                     PIC X(30).
       FD  REL-FILE
               BLOCK CONTAINS 8 RECORDS
               LABEL RECORDS ARE STANDARD
               DATA RECORD IS REL-RECORD.
       01  REL-RECORD                     PIC X(30).
       FD  INX-FILE
               BLOCK CONTAINS 8 RECORDS
               LABEL RECORDS ARE STANDARD
               DATA RECORD IS INX-RECORD.
       01  INX-RECORD.                     
           03  INX-KEY                    PIC X(3).
           03  FILLER                     PIC X(6).
           03  ALT-KEY                    PIC X(3).
           03  INX-DAT                    PIC X(3).
           03  FILLER                     PIC X(15).
      *
       WORKING-STORAGE SECTION.
       77  REL-KEY                        PIC 999.
       77  KEY-NUM                        PIC 999.
       77  RETURN-KEY                     PIC X.
       77  FUNCTION-NUMBER                PIC 9.
       77  COUNTER                        PIC 999.
       77  ALT-COUNT                      PIC 999.
      /
      *
       PROCEDURE DIVISION.
       SECTION-1 SECTION 1.
       DISPLAY-MENU.
           DISPLAY "RMCOBOL FILE SYSTEM TEST"
               LINE 2 POSITION 10 ERASE.
           DISPLAY "1. SEQUENTIAL FILE TEST" LINE 4 POSITION 10.
           DISPLAY "2. RELATIVE FILE TEST" POSITION 10.
           DISPLAY "3. INDEXED FILE TEST" POSITION 10.
           DISPLAY "4. EXIT PROGRAM" POSITION 10.
       ACCEPT-FUNCTION-NUMBER.
           DISPLAY "ENTER FUNCTION NUMBER    " LINE 16 POSITION 40.
           ACCEPT FUNCTION-NUMBER LINE 16 POSITION 66 TAB.
           DISPLAY "                           " LINE 16 POSITION 40.
           GO TO PARA-3, PARA-2, PARA-1, EXIT-PARA
               DEPENDING ON FUNCTION-NUMBER.
           GO TO ACCEPT-FUNCTION-NUMBER.
       DISPLAY-MENU-LOOP.
           DISPLAY "HIT ANY KEY TO CONTINUE"
               LINE 22 POSITION 40.
           ACCEPT RETURN-KEY POSITION 0.
           GO TO DISPLAY-MENU.
       RESET-COUNTER.
           MOVE ZERO TO COUNTER.
      /
       SECTION-2 SECTION 2.
       WRITE-INX-RECORD.
           ADD 1 TO COUNTER.
           COMPUTE ALT-COUNT = 101 - COUNTER.
           MOVE COUNTER TO INX-DAT.
           MOVE COUNTER TO INX-KEY.
           MOVE ALT-COUNT TO ALT-KEY.
           DISPLAY "WRITING BY PRIME KEY WITH ALTERNATE "
               LINE 11 POSITION 10.
           DISPLAY COUNTER POSITION 0.
           WRITE INX-RECORD.
       READ-BY-INX-KEY.
           ADD 1 TO KEY-NUM.
           MOVE KEY-NUM TO INX-KEY.
           DISPLAY "READING BY PRIME KEY "
               LINE 12 POSITION 10.
           DISPLAY KEY-NUM POSITION 0.
           READ INX-FILE RECORD
               KEY IS INX-KEY
               INVALID KEY ADD 1 TO COUNTER.
           IF INX-DAT NOT = KEY-NUM ADD 1 TO COUNTER.
       READ-BY-ALT-KEY.
           MOVE KEY-NUM TO ALT-KEY.
           READ INX-FILE RECORD
               KEY IS ALT-KEY
               INVALID KEY ADD 1 TO COUNTER.
           COMPUTE ALT-COUNT = 101 - KEY-NUM.
           DISPLAY "READING BY ALTERNATE KEY "
               LINE 13 POSITION 10.
           DISPLAY ALT-COUNT POSITION 0.
           IF INX-DAT NOT = ALT-COUNT ADD 1 TO COUNTER.
           SUBTRACT 1 FROM KEY-NUM.
       WRITE-REL-RECORD.
           MOVE SPACES TO REL-RECORD.
           MOVE COUNTER TO REL-KEY.
           MOVE COUNTER TO REL-RECORD.
           DISPLAY "WRITING RELATIVE RECORD "
               LINE 12 POSITION 10.
           DISPLAY COUNTER POSITION 0.
           WRITE REL-RECORD.
           ADD 2 TO COUNTER.
       READ-REL-RECORD.
           ADD 1 TO KEY-NUM.
           MOVE KEY-NUM TO REL-KEY.
           DISPLAY "READING RELATIVE RECORD "
               LINE 13 POSITION 10.
           DISPLAY KEY-NUM POSITION 0.
           READ REL-FILE RECORD 
               INVALID KEY ADD 1 TO COUNTER.
           IF REL-RECORD NOT = REL-KEY ADD 1 TO COUNTER.
       WRITE-SEQ-RECORD.
           MOVE "SEQ RECORD" TO SEQ-RECORD.
           ADD 1 TO KEY-NUM.
           DISPLAY "WRITING SEQUENTIAL RECORDS "
               LINE 12 POSITION 10.
           DISPLAY KEY-NUM POSITION 0.
           WRITE SEQ-RECORD.
       READ-SEQ-RECORD.
           READ SEQ-FILE RECORD.
           ADD 1 TO KEY-NUM.
           DISPLAY "READING SEQUENTIAL RECORD "
               LINE 13 POSITION 10.
           DISPLAY KEY-NUM POSITION 0.
           IF SEQ-RECORD NOT = "SEQ RECORD"
               ADD 1 TO COUNTER.
      /
       SECTION-51 SECTION 51.
       PARA-1.
           PERFORM RESET-COUNTER.
           OPEN OUTPUT INX-FILE.
           PERFORM WRITE-INX-RECORD 100 TIMES.
           CLOSE INX-FILE.
           OPEN INPUT INX-FILE.
           PERFORM RESET-COUNTER.
           MOVE 0 TO KEY-NUM.
           PERFORM READ-BY-INX-KEY 100 TIMES.
           PERFORM READ-BY-ALT-KEY 100 TIMES.
           CLOSE INX-FILE.
           IF COUNTER = 0
               DISPLAY "PASSED" LINE 14 POSITION 10
           ELSE
               DISPLAY "FAILED" LINE 14 POSITION 10.
           GO TO DISPLAY-MENU-LOOP.
      *
       SECTION-52 SECTION 52.
       PARA-2.
           OPEN OUTPUT REL-FILE.
           MOVE 1 TO COUNTER.
           PERFORM WRITE-REL-RECORD 50 TIMES.
           MOVE 2 TO COUNTER.
           PERFORM WRITE-REL-RECORD 50 TIMES.
           PERFORM RESET-COUNTER.
           CLOSE REL-FILE.
           OPEN INPUT REL-FILE.
           MOVE 0 TO KEY-NUM.
           PERFORM READ-REL-RECORD 100 TIMES.
           CLOSE REL-FILE.
           IF COUNTER = 0
               DISPLAY "PASSED" LINE 14 POSITION 10
           ELSE
               DISPLAY "FAILED" LINE 14 POSITION 10.
           GO TO DISPLAY-MENU-LOOP.
      /
      *
       SECTION-53 SECTION 53.
       PARA-3.
           OPEN OUTPUT SEQ-FILE.
           MOVE 0 TO KEY-NUM.
           PERFORM WRITE-SEQ-RECORD 100 TIMES.
           PERFORM RESET-COUNTER.
           CLOSE SEQ-FILE.
           OPEN INPUT SEQ-FILE.
           MOVE 0 TO KEY-NUM.
           PERFORM READ-SEQ-RECORD 100 TIMES.
           CLOSE SEQ-FILE.
           IF COUNTER = 0
               DISPLAY "PASSED" LINE 14 POSITION 10
           ELSE 
               DISPLAY "FAILED" LINE 14 POSITION 10.
           GO TO DISPLAY-MENU-LOOP.
      *
       SECTION-54 SECTION 54.
       PARA-4.
           DISPLAY "Test not Ready" LINE 10 POSITION 34 ERASE.
           GO TO DISPLAY-MENU-LOOP.
      *
       EXIT-PARA.
           EXIT PROGRAM.
      *
       END PROGRAM.
