000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID.  RMCAL2.
000015*                 Ver. 2.0B
000030*             (INDEXED-SEQUENTIAL-ACCESS-UTILITY
000040*             (FOR PRE-ALLOCATION OF INDEXED FILES
000050*             (UNDER RM/COBOL VERSION 2 FORMATS
000060*     Date Revised    08 Mar 1984
000070 ENVIRONMENT DIVISION.
000080 CONFIGURATION SECTION.
000090 SOURCE-COMPUTER.  RMCOBOL.
000100 OBJECT-COMPUTER.  RMCOBOL.
000120 INPUT-OUTPUT SECTION.
000130 FILE-CONTROL.
000140 SELECT SEQ-FILE-1 ASSIGN TO RANDOM FILE-NAME-1
000150     ORGANIZATION IS BINARY SEQUENTIAL.
000160 SELECT SEQ-FILE-2 ASSIGN TO RANDOM FILE-NAME-2
000170     ORGANIZATION IS BINARY SEQUENTIAL.
000200*
000210 DATA DIVISION.
000230 FILE SECTION.
000240 FD  SEQ-FILE-1.
000250 01  SEQ-REC-1                         PIC X(256).
000260 FD  SEQ-FILE-2.
000270 01  SEQ-REC-2                         PIC X(256).
000290/
000300 WORKING-STORAGE SECTION.
000310*
000320*   (initial and calculation variables)
000330*
000360 77  RETURN-KEY                        PIC X.
000365 77  CORRECTION-KEY                    PIC X.
000367 77  FORMAT-TYPE                       PIC 9.
000368 77  COUNTER                           PIC 9(5).
000370 77  DUMMY                             PIC 99.
000371 77  I                                 PIC 99    VALUE 0.
       77  J                                 PIC 99    VALUE 0.
       77  K                                 PIC 99    VALUE 6.
       77  L                                 PIC 99    VALUE 6.
       77  M                                 PIC 99    VALUE 0.
       77  N                                 PIC 99    VALUE 0.
000372 77  PRI-TOTAL                         PIC 9(5).
000373 77  ALT-TOTAL                         PIC 9(5)  VALUE 0.
000375 77  PRI-KEYS-PER-NODE                 PIC 9(6).
000380 77  PRI-KEY-NODE-NUM                  PIC 9(7).
000385 77  DUMMY-SIZE                        PIC S9(8).
000390 77  FREE-SEQ-REC-NUM                  PIC 9(7).
000391 77  TOTAL-DATA-SIZE                   PIC S9(10).
000392 77  TOTAL-NODE-SIZE                   PIC S9(7) VALUE 0.
000393 77  NEXT-AVAIL-DATA                   PIC S9(10).
000395 01  TABLE-1.
000397     02  ALT-KEYS-PER-NODE             PIC 9(6)
000398             OCCURS 14 TIMES.
000397 01  TABLE-2.
000398     02  ALT-KEY-NODE-NUM              PIC 9(7)
000399             OCCURS 14 TIMES.
000400*
000401*   (accept storage)
000402*
000403 77  FILE-NAME-1                       PIC X(19).
000404 77  FILE-NAME-2                       PIC X(19).
000406 77  FILE-SIZE                         PIC 9(10).
000407 77  DATA-REC-SIZE                     PIC 9(4).
000408 77  PRI-SIZE                          PIC 999.
000409 77  PRI-OFFSET                        PIC 9(4).
000411 77  ALT-KEYS                          PIC 99.
000412 77  ALT-NUM                           PIC 99.
000413 01  TABLE-3.
000414     02  ALT-KEY-TABLE OCCURS 14 TIMES.
000415         03  ALT-SIZE                  PIC 999.   
000416         03  ALT-OFFSET                PIC 9(4).
000417         03  DUP-NUM                   PIC X.
000448/
000449*
000450*    (header storage)
000451*
000452 01  HEADER-FORMAT.
000453     02  FIRST-BLOCK                             USAGE COMP-1.
000454         03  HEADER-CODE-WORD          PIC 9     VALUE 0.
000455         03  AUS-PER-HEADER            PIC 999.
000456         03  AUS-PER-DATA-REC          PIC 9(4).
000457         03  FREE-NODE-LIST-HEAD-1     PIC 9     VALUE 0.
000458         03  FREE-NODE-LIST-HEAD-2     PIC 9     VALUE 0.
000459         03  FREE-NODE-NUM             PIC 9     VALUE 0.
000460         03  FREE-REC-LIST-HEAD-1      PIC 9     VALUE 0.
000461         03  FREE-REC-LIST-HEAD-2      PIC 9     VALUE 0.
000462         03  FREE-REC-NUM              PIC 9     VALUE 0.
               03  TOTAL-NODE-SIZE-1         PIC 9(5).
               03  TOTAL-NODE-SIZE-2         PIC 9(5).
               03  NEXT-AVAIL-NODE-1         PIC 9     VALUE 0.
               03  NEXT-AVAIL-NODE-2         PIC 999   VALUE 513.
               03  TOTAL-DATA-SIZE-1         PIC 9(5).
               03  TOTAL-DATA-SIZE-2         PIC 9(5).
               03  NEXT-AVAIL-DATA-1         PIC 9(5).
               03  NEXT-AVAIL-DATA-2         PIC 9(5).
               03  RECORD-COUNT-1            PIC 9     VALUE 0.
               03  RECORD-COUNT-2            PIC 9     VALUE 0.
               03  NEXT-AVAIL-STAMP-1        PIC 9     VALUE 0.
               03  NEXT-AVAIL-STAMP-2        PIC 9     VALUE 0.
000468         03  FLAG-WORD                 PIC 9     VALUE 0.
000469         03  NUMBER-OF-KEYS            PIC 99.
000470     02  PRI-KEY-BLOCK.
000471         03  PRI-KEY-SIZE              PIC 999   USAGE COMP-1.
000472         03  PRI-KEY-OFFSET            PIC 9(4)  USAGE COMP-1.
000473         03  FILLER                    PIC X(6)
                       VALUE LOW-VALUES.
000474     02  TABLE-4.
000475         03  ALT-KEY-BLOCK OCCURS 14 TIMES.        
000476             04  ALT-KEY-SIZE          PIC 999   USAGE COMP-1.
000477             04  ALT-KEY-OFFSET        PIC 9(4)  USAGE COMP-1.
000478             04  FILLER                PIC X(6).
000479     02  DUM-REC                       PIC X(60)
                   VALUE LOW-VALUES.
      /
000800 PROCEDURE DIVISION.
000830 RESET-COUNTER.
000840     MOVE ZERO TO COUNTER.
000850 INIT-VARIABLE-FIELDS.
000860     ADD 1 TO COUNTER.
000870     MOVE LOW-VALUES TO ALT-KEY-BLOCK (COUNTER).
000880     IF COUNTER < 14 GO TO INIT-VARIABLE-FIELDS.
000900 DISPLAY-ALLOCATE-FUNCTION.
000905     DISPLAY "RM/COBOL Pre-Allocation Utility (Ver. 2.0)"
000907         LINE 1 ERASE.
000910     DISPLAY "This program will allocate an RM/COBOL"
000920         LINE 5 POSITION 20.
000930     DISPLAY "indexed data file according to the specifications"
000940         POSITION 12.
000950     DISPLAY "entered by the user. Make certain that approximate"
000960         POSITION 12.
000970     DISPLAY "numbers are large enough to account for expansion"
000980         POSITION 12.
000990     DISPLAY "of the file in the future." POSITION 12.
001000     DISPLAY "Hit any key to continue" LINE 23 POSITION 30.
001010     ACCEPT RETURN-KEY POSITION 0.
           DISPLAY "RM/COBOL Pre-Allocation Utility (Ver. 2.0)"
               LINE 1 ERASE.
           DISPLAY "(Cntrl-B for Back-Tab)" LINE 1 POSITION 51.
      *
       ACCEPT-FORMAT.
           MOVE 1 TO I.
           DISPLAY "Which format do you desire? " LINE 2.
           DISPLAY "(Single-file = 1 ; Dual-file = 2) " POSITION 0. 
           ACCEPT FORMAT-TYPE POSITION 0 TAB.
           IF FORMAT-TYPE NOT = 1 AND FORMAT-TYPE NOT = 2
               PERFORM INPUT-ERROR-1.
       INPUT-FILENAME-1.
           MOVE 2 TO I.
           DISPLAY "Indexed File Name? " LINE 3 ERASE EOS.
           DISPLAY "(with required index extension)" LINE 4.
           ACCEPT FILE-NAME-1 LINE 3 POSITION 20
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF FILE-NAME-1 = SPACES PERFORM INPUT-ERROR-1.
       INPUT-FILENAME-2.
           IF FORMAT-TYPE = 2
               MOVE 3 TO I
               DISPLAY "Data File Name? " LINE 3 POSITION 41
                   ERASE EOL
               DISPLAY "(same name with different extension)"
                   LINE 4 POSITION 41 ERASE EOS
               ACCEPT FILE-NAME-2 LINE 3 POSITION 57 TAB
                   ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF FORMAT-TYPE = 2 AND FILE-NAME-2 = SPACES
               PERFORM INPUT-ERROR-1.
      /
       INPUT-SPECS-1.
           MOVE 4 TO I.
           DISPLAY "Approximate # of Records" LINE 5 ERASE EOS.
           ACCEPT FILE-SIZE LINE 5 POSITION 27 CONVERT ECHO TAB
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF FILE-SIZE = 0 PERFORM INPUT-ERROR-1.
       INPUT-SPECS-2.
           MOVE 5 TO I.
           DISPLAY "Bytes per Data Record" LINE 5 POSITION 39
               ERASE EOS.
           ACCEPT DATA-REC-SIZE LINE 5 POSITION 62 CONVERT TAB ECHO
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF DATA-REC-SIZE > 4096 OR DATA-REC-SIZE = 0
               PERFORM INPUT-ERROR-1.
       INPUT-SPECS-3.
           MOVE 6 TO I.
           DISPLAY "Bytes per Primary Key" LINE 6 ERASE EOS.
           ACCEPT PRI-SIZE LINE 6 POSITION 24 CONVERT ECHO TAB
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF PRI-SIZE > 244 OR PRI-SIZE = 0
               OR PRI-SIZE > DATA-REC-SIZE PERFORM INPUT-ERROR-1.
       INPUT-SPECS-4.
           MOVE 7 TO I.
           DISPLAY "Offset(Rel 0)" LINE 6 POSITION 30 ERASE EOS.
           ACCEPT PRI-OFFSET LINE 6 POSITION 45 CONVERT ECHO TAB
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           ADD PRI-SIZE, PRI-OFFSET GIVING PRI-TOTAL.
           IF PRI-TOTAL > DATA-REC-SIZE OR PRI-OFFSET > 4095
               PERFORM INPUT-ERROR-1.
       INPUT-SPECS-5.
           MOVE 8 TO I.
           DISPLAY "# of Alt Keys" LINE 6 POSITION 52 ERASE EOS.
           ACCEPT ALT-KEYS LINE 6 POSITION 67 CONVERT ECHO TAB
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF ALT-KEYS > 14 PERFORM INPUT-ERROR-1.
           MOVE ALT-KEYS TO ALT-NUM.
           MOVE 6 TO K.
           MOVE 0 TO M.
       INPUT-ALT-SPECS.
           PERFORM ALT-KEY-SPECS ALT-NUM TIMES.
           IF M < ALT-NUM SUBTRACT M FROM ALT-NUM
               GO TO INPUT-ALT-SPECS.
           PERFORM CHECK-PAGE.
      /
       MAKE-FILE.
           DISPLAY "Working...." LINE 23 POSITION 30 ERASE EOS.
001054     OPEN OUTPUT SEQ-FILE-1.
001055     PERFORM BUILD-HEADER.
001170 BUILD-ISAM-FILE-1.
001200     MOVE HEADER-FORMAT TO SEQ-REC-1.
001210     PERFORM WRITE-SEQ-REC-1.
001217     MOVE LOW-VALUES TO SEQ-REC-1.
001230     COMPUTE FREE-SEQ-REC-NUM ROUNDED = TOTAL-DATA-SIZE / 256.
001240     PERFORM WRITE-SEQ-REC-1 FREE-SEQ-REC-NUM TIMES.
001390     CLOSE SEQ-FILE-1.
001395     DISPLAY SPACES LINE 23 POSITION 30 SIZE 12.
001400     GO TO EXIT-PARA.
       BUILD-ISAM-FILE-2.
           MOVE HEADER-FORMAT TO SEQ-REC-1.
           PERFORM WRITE-SEQ-REC-1.
           MOVE LOW-VALUES TO SEQ-REC-1.
           COMPUTE FREE-SEQ-REC-NUM = TOTAL-NODE-SIZE / 256.
           PERFORM WRITE-SEQ-REC-1 FREE-SEQ-REC-NUM TIMES.
           CLOSE SEQ-FILE-1.
           OPEN OUTPUT SEQ-FILE-2.
           COMPUTE TOTAL-DATA-SIZE = DATA-REC-SIZE * FILE-SIZE .
           COMPUTE FREE-SEQ-REC-NUM ROUNDED = TOTAL-DATA-SIZE / 256 .
           MOVE LOW-VALUES TO SEQ-REC-2.
           PERFORM WRITE-SEQ-REC-2 FREE-SEQ-REC-NUM TIMES.
           CLOSE SEQ-FILE-2.
           DISPLAY SPACES LINE 23 POSITION 30 SIZE 12.
           DISPLAY "File Successfully Pre-Allocated"
               LINE 23 POSITION 40.
       EXIT-PARA.
           EXIT PROGRAM.
       STOP-PARA.
           STOP RUN.
      /
       ALT-KEY-SPECS.
           ADD 1 TO M.
           ADD 1 TO K.
           PERFORM ALT-KEY-SPECS-1 THRU ALT-KEY-SPECS-3.
       ALT-KEY-SPECS-1.
           MOVE 9 TO I.
           DISPLAY "Bytes per Alt Key #" LINE K ERASE EOS. 
           DISPLAY M LINE K POSITION 20.
           ACCEPT ALT-SIZE (M) LINE K POSITION 24 CONVERT ECHO TAB 
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF ALT-SIZE (M) > 244 OR ALT-SIZE (M) = 0 OR
               ALT-SIZE (M) > DATA-REC-SIZE PERFORM INPUT-ERROR-1.
       ALT-KEY-SPECS-2.
           MOVE 10 TO I.
           DISPLAY "Offset(Rel 0)" LINE K POSITION 30.
           ACCEPT ALT-OFFSET (M) LINE K POSITION 45 CONVERT ECHO TAB 
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           ADD ALT-SIZE (M), ALT-OFFSET (M) GIVING ALT-TOTAL.
           IF ALT-TOTAL > DATA-REC-SIZE OR ALT-OFFSET (M) > 4095
               PERFORM INPUT-ERROR-1.
       ALT-KEY-SPECS-3.
           MOVE 11 TO I.
           DISPLAY "Duplicates? " LINE K POSITION 52 ERASE EOS.
           ACCEPT DUP-NUM (M) LINE K POSITION 65 TAB 
               ON EXCEPTION DUMMY PERFORM I-BACK-TAB.
           IF DUP-NUM (M) NOT = "Y" AND DUP-NUM (M) NOT = "y"
               AND DUP-NUM (M) NOT = "N" AND DUP-NUM (M) NOT = "n"
               PERFORM INPUT-ERROR-1.
           IF M = ALT-NUM MOVE 0 TO ALT-NUM GO TO INPUT-ALT-SPECS.
      /
       WRITE-SEQ-REC-1.
           WRITE SEQ-REC-1.
       WRITE-SEQ-REC-2.
           WRITE SEQ-REC-2.
001515 BUILD-HEADER.
001520     COMPUTE AUS-PER-HEADER = (ALT-KEYS * 10) + 56.
001530     ADD ALT-KEYS, 1 GIVING NUMBER-OF-KEYS.
001540     MOVE DATA-REC-SIZE TO AUS-PER-DATA-REC.
001550     MOVE PRI-SIZE TO PRI-KEY-SIZE.
001560     MOVE PRI-OFFSET TO PRI-KEY-OFFSET.
           IF FORMAT-TYPE = 2
               MOVE 1 TO HEADER-CODE-WORD
               MOVE 32767 TO TOTAL-NODE-SIZE-1
               MOVE -2 TO TOTAL-NODE-SIZE-2
               MOVE 32767 TO TOTAL-DATA-SIZE-1
               MOVE -2 TO TOTAL-DATA-SIZE-2
               MOVE 0 TO NEXT-AVAIL-DATA-1
               MOVE 1 TO NEXT-AVAIL-DATA-2.
001562     PERFORM RESET-COUNTER.
001563     PERFORM CALC-ALT-VALUES ALT-KEYS TIMES.
001565     PERFORM CALC-WORD-VALUES.
001620 CALC-ALT-VALUES.
001640     ADD 1 TO COUNTER.
001650     IF DUP-NUM (COUNTER) = "Y" OR DUP-NUM (COUNTER) = "y"
001652         ADD ALT-SIZE (COUNTER), 4096
001653             GIVING ALT-KEY-SIZE (COUNTER)
001654         ELSE MOVE ALT-SIZE (COUNTER)
001655             TO ALT-KEY-SIZE (COUNTER).
001660     MOVE ALT-OFFSET (COUNTER)
001665         TO ALT-KEY-OFFSET (COUNTER).
       CALC-WORD-VALUES.
           PERFORM CALC-KEYS-PER-NODE.
           COMPUTE PRI-KEY-NODE-NUM ROUNDED =
               (3 * FILE-SIZE) / (2 * PRI-KEYS-PER-NODE).
           ADD PRI-KEY-NODE-NUM TO TOTAL-NODE-SIZE.
           PERFORM RESET-COUNTER.
           PERFORM CALC-ALT-KEY-NODE-NUM ALT-KEYS TIMES.
           ADD 1 TO TOTAL-NODE-SIZE.
           MULTIPLY 512 BY TOTAL-NODE-SIZE.
           IF FORMAT-TYPE = 2 GO TO BUILD-ISAM-FILE-2.
           PERFORM CALC-TOTAL-DATA-SIZE.
           PERFORM CALC-NEXT-AVAIL-DATA.
           PERFORM RESET-COUNTER.
           IF TOTAL-NODE-SIZE > 32767
               PERFORM FIX-TOTAL-NODE-SIZE
                   UNTIL TOTAL-NODE-SIZE < 32768.
           MOVE COUNTER TO TOTAL-NODE-SIZE-1.
           MOVE TOTAL-NODE-SIZE TO TOTAL-NODE-SIZE-2.
      /
       CALC-TOTAL-DATA-SIZE.
           COMPUTE TOTAL-DATA-SIZE =
               (DATA-REC-SIZE * FILE-SIZE) + TOTAL-NODE-SIZE .
           PERFORM RESET-COUNTER.
           IF TOTAL-DATA-SIZE > 32767
               PERFORM FIX-TOTAL-DATA-SIZE
                   UNTIL TOTAL-DATA-SIZE < 32768.
           MOVE COUNTER TO TOTAL-DATA-SIZE-1.
           MOVE TOTAL-DATA-SIZE TO TOTAL-DATA-SIZE-2.
001670 CALC-KEYS-PER-NODE.
001673     DIVIDE 2 INTO PRI-SIZE ROUNDED.
001676     MULTIPLY 2 BY PRI-SIZE.
001679     COMPUTE PRI-KEYS-PER-NODE ROUNDED =
001682         (504 / (PRI-SIZE + 8)) - 0.5 .
001685     PERFORM RESET-COUNTER.
001686     PERFORM CALC-ALT-KEYS-PER-NODE ALT-KEYS TIMES.
001695 CALC-ALT-KEYS-PER-NODE.
001696     ADD 1 TO COUNTER.
001697     DIVIDE 2 INTO ALT-SIZE (COUNTER) ROUNDED.
001700     MULTIPLY 2 BY ALT-SIZE (COUNTER).
001701     IF DUP-NUM (COUNTER) = "Y" OR DUP-NUM (COUNTER) = "y"
               ADD 4 TO ALT-SIZE (COUNTER).
001702     COMPUTE ALT-KEYS-PER-NODE (COUNTER) ROUNDED =
001703         (504 / (ALT-SIZE (COUNTER) + 8)) - 0.5 .
001705 CALC-ALT-KEY-NODE-NUM.
001706     ADD 1 TO COUNTER.
001707     COMPUTE ALT-KEY-NODE-NUM (COUNTER) ROUNDED =
001709         (3 * FILE-SIZE) / (2 * ALT-KEYS-PER-NODE (COUNTER)).
001711     ADD ALT-KEY-NODE-NUM (COUNTER) TO TOTAL-NODE-SIZE.
001712 CALC-NEXT-AVAIL-DATA.
           COMPUTE NEXT-AVAIL-DATA = TOTAL-NODE-SIZE + 1 .
           PERFORM RESET-COUNTER.
           IF NEXT-AVAIL-DATA > 32767
               PERFORM FIX-NEXT-AVAIL-DATA
                   UNTIL NEXT-AVAIL-DATA < 32768.
           MOVE COUNTER TO NEXT-AVAIL-DATA-1.
           MOVE NEXT-AVAIL-DATA TO NEXT-AVAIL-DATA-2.
001830 FIX-TOTAL-NODE-SIZE.
001832     COMPUTE DUMMY-SIZE = TOTAL-NODE-SIZE - 65536.
001834     IF DUMMY-SIZE > -1 ADD 1 TO COUNTER. 
001838     MOVE DUMMY-SIZE TO TOTAL-NODE-SIZE.
001840 FIX-TOTAL-DATA-SIZE.
001842     COMPUTE DUMMY-SIZE = TOTAL-DATA-SIZE - 65536.
001844     IF DUMMY-SIZE > -1 ADD 1 TO COUNTER.
001846     MOVE DUMMY-SIZE TO TOTAL-DATA-SIZE.
001850 FIX-NEXT-AVAIL-DATA.
001852     COMPUTE DUMMY-SIZE = NEXT-AVAIL-DATA - 65536.
001855     IF DUMMY-SIZE > -1 ADD 1 TO COUNTER.
001858     MOVE DUMMY-SIZE TO NEXT-AVAIL-DATA.
      /
       I-BACK-TAB.
           IF DUMMY = 02 
               MOVE M TO N MOVE K TO L
               GO TO U1, U1, U2, U3-B, U4, U5, U6, U7, U8-I, U9, U10
                   DEPENDING ON I
               ELSE PERFORM INPUT-ERROR-1.
       J-BACK-TAB.
           IF DUMMY = 02
               SUBTRACT 1 FROM J
               GO TO U1, U2, U3-B, U4, U5, U6, U7, U8-J, U9, U10
                   DEPENDING ON J
               ELSE PERFORM INPUT-ERROR-2.
       U3-B.
           IF FORMAT-TYPE = 1 GO TO U2
               ELSE GO TO U3.
       U8-I.
           IF K > 7 COMPUTE L = K - 1 COMPUTE N = M - 1 GO TO U11
               ELSE GO TO U8.
       U8-J.
           IF L > 7 SUBTRACT 1 FROM L SUBTRACT 1 FROM N GO TO U11
               ELSE GO TO U8.
       INPUT-ERROR-1.
           DISPLAY "Input Error !" LINE 23 POSITION 30.
           DISPLAY "Hit any key to start again" LINE 24 POSITION 30.
           ACCEPT RETURN-KEY POSITION 0.
           GO TO ACCEPT-FORMAT, INPUT-FILENAME-1, INPUT-FILENAME-2,
               INPUT-SPECS-1, INPUT-SPECS-2, INPUT-SPECS-3,
               INPUT-SPECS-3, INPUT-SPECS-5, ALT-KEY-SPECS-1
               ALT-KEY-SPECS-1, ALT-KEY-SPECS-3 DEPENDING ON I.
       INPUT-ERROR-2.
           DISPLAY "Input Error !" LINE 23 POSITION 30.
           DISPLAY "Hit any key to start again" LINE 24 POSITION 30.
           ACCEPT RETURN-KEY POSITION 0.
           DISPLAY " " LINE 23 POSITION 30 ERASE EOS.
           GO TO U1, U2, U3, U4, U5, U6, U6, U8, U9, U9, U11
               DEPENDING ON J.
       CHECK-PAGE.
           DISPLAY "Is the above information correct ?"
               LINE 23 POSITION 30.
           DISPLAY "(Enter N to correct, any other key to continue)"
               LINE 24 POSITION 30.
           ACCEPT CORRECTION-KEY POSITION 0.
           IF CORRECTION-KEY = "N" OR CORRECTION-KEY = "n"
               DISPLAY " " LINE 23 POSITION 30 ERASE EOS
               GO TO U1.
      /
       U1.
           MOVE 1 TO J.
           ACCEPT FORMAT-TYPE LINE 2 POSITION 63 UPDATE.
           IF FORMAT-TYPE NOT = 1 AND FORMAT-TYPE NOT = 2
               PERFORM INPUT-ERROR-2.
       U2.
           MOVE 2 TO J.
           ACCEPT FILE-NAME-1 LINE 3 POSITION 20 UPDATE
               ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF FILE-NAME-1 = SPACES PERFORM INPUT-ERROR-2.
       U3.
           MOVE 3 TO J.
           IF J > I GO TO INPUT-FILENAME-2.
           IF FORMAT-TYPE = 1
               DISPLAY " " LINE 3 POSITION 41 ERASE EOL.
               DISPLAY " " LINE 4 POSITION 41 ERASE EOL.
           IF FORMAT-TYPE = 2
               DISPLAY "Data File Name? " LINE 3 POSITION 41
               DISPLAY "(same name with different extension)"
                   LINE 4 POSITION 41 
               ACCEPT FILE-NAME-2 LINE 3 POSITION 57 UPDATE
                   ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF FORMAT-TYPE = 2 AND FILE-NAME-2 = SPACES
               PERFORM INPUT-ERROR-2.
       U4.
           MOVE 4 TO J.
           IF J > I GO TO INPUT-SPECS-1.
           ACCEPT FILE-SIZE LINE 5 POSITION 27 CONVERT ECHO 
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF FILE-SIZE = 0 PERFORM INPUT-ERROR-2.
       U5.
           MOVE 5 TO J.
           IF J > I GO TO INPUT-SPECS-2.
           ACCEPT DATA-REC-SIZE LINE 5 POSITION 62 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF DATA-REC-SIZE = 0 OR DATA-REC-SIZE > 4096
               PERFORM INPUT-ERROR-2.
       U6.
           MOVE 6 TO J.
           IF J > I GO TO INPUT-SPECS-3.
           ACCEPT PRI-SIZE LINE 6 POSITION 24 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF PRI-SIZE > 244 OR PRI-SIZE = 0
               OR PRI-SIZE > DATA-REC-SIZE PERFORM INPUT-ERROR-2.
      /
       U7.
           MOVE 7 TO J.
           IF J > I GO TO INPUT-SPECS-4.
           ACCEPT PRI-OFFSET LINE 6 POSITION 45 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           ADD PRI-SIZE, PRI-OFFSET GIVING PRI-TOTAL.
           IF PRI-TOTAL > DATA-REC-SIZE OR PRI-OFFSET > 4095
               PERFORM INPUT-ERROR-2.
       U8.
           MOVE 8 TO J.
           IF J > I GO TO INPUT-SPECS-5.
           ACCEPT ALT-KEYS LINE 6 POSITION 67 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF ALT-KEYS > 14 PERFORM INPUT-ERROR-2.
           MOVE ALT-KEYS TO ALT-NUM.
           IF ALT-NUM = 0 MOVE 0 TO N MOVE 6 TO L
               GO TO UPDATE-CHECK.
           IF M = 0 MOVE 6 TO K GO TO INPUT-ALT-SPECS.
           MOVE 1 TO N MOVE 7 TO L.
       U9.
           MOVE 9 TO J.
           IF N = M AND J > I GO TO ALT-KEY-SPECS-1.
           ACCEPT ALT-SIZE (N) LINE L POSITION 24 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF ALT-SIZE (N) = 0 OR ALT-SIZE (N) > 244 OR
               ALT-SIZE (N) > DATA-REC-SIZE PERFORM INPUT-ERROR-2.
       U10.
           MOVE 10 TO J.
           IF N = M AND J > I GO TO ALT-KEY-SPECS-2.
           ACCEPT ALT-OFFSET (N) LINE L POSITION 45 CONVERT ECHO
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           ADD ALT-SIZE (N), ALT-OFFSET (N) GIVING ALT-TOTAL.
           IF ALT-TOTAL > DATA-REC-SIZE OR ALT-OFFSET (N) > 4095
               PERFORM INPUT-ERROR-2.
       U11.
           MOVE 11 TO J.
           IF N = M AND J > I GO TO ALT-KEY-SPECS-3.
           ACCEPT DUP-NUM (N) LINE L POSITION 65
               UPDATE ON EXCEPTION DUMMY PERFORM J-BACK-TAB.
           IF DUP-NUM (N) NOT = "Y" AND DUP-NUM (N) NOT = "y"
               AND DUP-NUM (N) NOT = "N" AND DUP-NUM (N) NOT = "n"
               PERFORM INPUT-ERROR-2.
       UPDATE-CHECK.
           IF N = ALT-NUM
               MOVE N TO M MOVE L TO K MOVE 0 TO ALT-NUM
               ADD 1 TO L DISPLAY " " LINE L ERASE EOS
               GO TO INPUT-ALT-SPECS.
           IF N < M ADD 1 TO N ADD 1 TO L GO TO U9.
           IF N = M SUBTRACT M FROM ALT-NUM GO TO INPUT-ALT-SPECS.
      *
       END PROGRAM.
