I'm trying to search a table, but it keeps abending. I'm very new to COBOL and I'm not sure if I'm just making a simple mistake. When I try to debug, it looks as if the parish codes match, so I'm not sure why it's not outputting the territory code. The instructions and my code for this routine are below in case it helps. I know I'm missing alot (like the counts) but I'm just trying to get some output first. Any help would be appreciated!
Read each record. If record type is 94, use SEARCH verb to locate parish code in parish/territory table and find territory code. Add territory code to the output record and write the record to disk.
If the parish is found in the parish/territory table, increment the count for that territory in the territory table.
If the parish is not in the parish/territory table, then abend the program.
Print each territory and the corresponding number of policies in that territory to the report.
Print counts of total records processed and total policies processed to the report.
FILE SECTION. FD REPORT-FILE LABEL RECORDS ARE OMITTED DATA RECORD IS REPORT-RECORD. 01 REPORT-RECORD PIC X(132). FD PRINT-FILE LABEL RECORDS ARE OMITTED DATA RECORD IS PRINT-RECORD. 01 PRINT-RECORD PIC X(132). FD INPUT-FILE LABEL RECORD IS STANDARD. COPY TRNREC94. EJECT WORKING-STORAGE SECTION. 01 record-ws. 05 rec-record-type pic x(2) read input-file 05 rec-policy-number pic x(8) 05 filler pic x(5) 05 rec-parish-code pic x(3) 05 filler pic x(1) 05 rec-territory-code pic x(1) 05 filler pic x(60) 01 HEADER. 05 FILLER PIC X(8) VALUE 'TSTHC020'. 05 FILLER PIC X(30) VALUE SPACES. 05 FILLER PIC X(41) VALUE 'LOUISIANA FARM BUREAU INSURANCE COMPANIES'. 05 FILLER PIC X(30) VALUE SPACES. 05 FILLER PIC X(5) VALUE 'PAGE '. 05 PRINT-PAGE-NUMBER PIC ZZZZZZ9. 01 HEADER-LINE-2. 05 FILLER PIC X(10) VALUE '10/22/2013'. 01 DETAIL-LINE. 05 DET-TERRITORY PIC X(2). 05 DET-NUMBER-POLICIES PIC X(2). 01 COLUMN-LINE. 05 FILLER PIC X(9) VALUE 'TERRITORY'. 05 FILLER PIC X(10) VALUE SPACES. 05 FILLER PIC X(18) VALUE 'NUMBER OF POLICIES'. 01 TOTAL-LINE. 05 FILLER PIC X(26) VALUE 'TOTAL RECORDS PROCESSED IS'. 05 TOTAL-RECORDS PIC X(3). 05 FILER PIC X(32) VALUE 'AND TOTAL POLICIES PROCESSED IS'. 05 TOTAL-POLICIES PIC X(3). 01 PROG-ID. 05 FILLER PIC X(50) VALUE 'PROGRAM - TSTXX002- WORKING STORAGE STARTS HERE'. 01 MISC-VARIABLES-SW. 05 END-OF-FILE-SW PIC XXX. 88 ALL-RECORDS-ARE-PROCESSED VALUE 'YES'. 88 MORE-RECORDS VALUE 'NO'. 01 FILE-STATUS-VALUES. 05 FILE-STATUS PIC 99. 88 SUCCESSFUL-READ VALUE 0. 88 SUCCESSFUL-START VALUE 0. 88 SUCCESSFUL-WRITE VALUE 0. 88 SUCCESSFUL-DELETE VALUE 0. 88 SUCCESSFUL-OPEN VALUE 0. 88 SUCCESSFUL-CLOSE VALUE 0. 88 END-OF-FILE VALUE 10. 88 RECORD-NOT-FOUND VALUE 23. 05 PAGE-CONTROLLERS. 10 A-LINE-COUNT PIC 999 COMP-3 VALUE 0. 10 A-PAGE-COUNT PIC 999 COMP-3 VALUE 0. 10 A-DISK-COUNTER PIC 9(5) COMP-3 VALUE 0. 01 TABLES. 05 T1-TERRITORY-VALUES. 10 FILLER PIC X(4) VALUE '0101'. 10 FILLER PIC X(4) VALUE '0207'. 10 FILLER PIC X(4) VALUE '0307'. 10 FILLER PIC X(4) VALUE '0409'. 10 FILLER PIC X(4) VALUE '0509'. 10 FILLER PIC X(4) VALUE '0609'. 10 FILLER PIC X(4) VALUE '0709'. 10 FILLER PIC X(4) VALUE '0801'. 10 FILLER PIC X(4) VALUE '0901'. 10 FILLER PIC X(4) VALUE '1001'. 10 FILLER PIC X(4) VALUE '1104'. 10 FILLER PIC X(4) VALUE '1204'. 10 FILLER PIC X(4) VALUE '1305'. 10 FILLER PIC X(4) VALUE '1405'. 10 FILLER PIC X(4) VALUE '1506'. 10 FILLER PIC X(4) VALUE '1606'. 10 FILLER PIC X(4) VALUE '1707'. 10 FILLER PIC X(4) VALUE '1802'. 10 FILLER PIC X(4) VALUE '1902'. 10 FILLER PIC X(4) VALUE '2002'. 10 FILLER PIC X(4) VALUE '2103'. 10 FILLER PIC X(4) VALUE '2208'. 10 FILLER PIC X(4) VALUE '2308'. 10 FILLER PIC X(4) VALUE '2409'. 10 FILLER PIC X(4) VALUE '2506'. 10 FILLER PIC X(4) VALUE '2605'. 10 FILLER PIC X(4) VALUE '2704'. 10 FILLER PIC X(4) VALUE '2804'. 10 FILLER PIC X(4) VALUE '2903'. 10 FILLER PIC X(4) VALUE '3003'. 05 T1-TERRITORY-TABLE REDEFINES T1-TERRITORY-VALUES. 10 T1-ENTRY OCCURS 30 TIMES INDEXED BY T1-INDEX. 15 T1-PARISH PIC XXX. 15 T1-TERRITORY PIC X. 05 T2-TERRITORY-COUNT. 10 FILLER PIC X(4) VALUE '1 '. 10 FILLER PIC X(4) VALUE '2 '. 10 FILLER PIC X(4) VALUE '3 '. 10 FILLER PIC X(4) VALUE '4 '. 10 FILLER PIC X(4) VALUE '5 '. 10 FILLER PIC X(4) VALUE '6 '. 10 FILLER PIC X(4) VALUE '7 '. 10 FILLER PIC X(4) VALUE '8 '. 10 FILLER PIC X(4) VALUE '9 '. 05 T2-TERRITORY-TABLE REDEFINES T2-TERRITORY-COUNT. 10 T2-ENTRY OCCURS 9 TIMES INDEXED BY T2-INDEX. 15 T2-TERRITORY-CODE PIC X. 15 T2-TERRITORY-COUNTER PIC XXX. PROCEDURE DIVISION. A000-MAINLINE. PERFORM B000-OPENING-PROCEDURE. PERFORM B110-PRINT-HEADINGS. PERFORM B300-READ-FILE. PERFORM B500-MAIN-PROCEDURE UNTIL END-OF-FILE-SW = 'YES'. PERFORM B100-CLOSING-PROCEDURE. STOP RUN. B000-OPENING-PROCEDURE. OPEN OUTPUT REPORT-FILE. OPEN OUTPUT PRINT-FILE. OPEN I-O INPUT-FILE. B100-CLOSING-PROCEDURE. PERFORM B800-PRINT-TOTAL-LINE. CLOSE REPORT-FILE. CLOSE PRINT-FILE. CLOSE INPUT-FILE. B200-PRINT-HEADER. MOVE HEADER TO PRINT-RECORD. WRITE PRINT-RECORD. MOVE HEADER-LINE-2 TO PRINT-RECORD. WRITE PRINT-RECORD BEFORE ADVANCING 1. B300-READ-FILE. READ INPUT-FILE NEXT RECORD AT END MOVE 'YES' TO END-OF-FILE-SW. B500-MAIN-PROCEDURE. PERFORM B600-SEARCH-TERRITORY PERFORM B300-READ-FILE. B600-SEARCH-TERRITORY. SET T1-INDEX TO 1. SEARCH T1-ENTRY AT END DISPLAY 'PARISH NOT FOUND IN TABLE' CALL 'CEE3ABD' USING BY VALUE 12 BY VALUE 1 WHEN REC-94-PARISH-CODE = T1-PARISH(T1-INDEX) MOVE T1-TERRITORY(T1-INDEX) TO DET-TERRITORY. B700-PRINT-DETAIL-LINE. MOVE DETAIL-LINE TO PRINT-RECORD. WRITE PRINT-RECORD BEFORE ADVANCING 1. B800-PRINT-TOTAL-LINE. MOVE A-LINE-COUNT TO TOTAL-RECORDS. MOVE TOTAL-LINE TO PRINT-RECORD. WRITE PRINT-RECORD AFTER ADVANCING 1. B900-PRINT-COLUMN-LINE. MOVE COLUMN-LINE TO PRINT-RECORD. WRITE PRINT-RECORD BEFORE ADVANCING 1. B110-PRINT-HEADINGS. ADD 1 TO A-PAGE-COUNT. MOVE A-PAGE-COUNT TO PRINT-PAGE-NUMBER. PERFORM B200-PRINT-HEADER. PERFORM B900-PRINT-COLUMN-LINE.
It think your problem is in not testing for the 94s. It is not enough to just include that one copybook.
B500-MAIN-PROCEDURE.
IF REC-94-TYPE EQUAL TO "94"
PERFORM B600-SEARCH-TERRITORY
END-IF
PERFORM B300-READ-FILE
.
Ideally you would have an 88 for the record-types, which you may find on another copybook for the same file.
Note that I have used a scope-delimiter (the END-IF) and limited the number of periods/full-stops to the mandatory one before a paragraph/SECTION starts or the end of the program is reached.
You are doing IO, you even have 88s set up, but you aren't doing any status checking on the IO. You should. Always.
Why have you opened your input for I-O? If you have an ordinary sequential file, read it, and write a new one. Otherwise you must create a back-up before your program runs. If you don't, your update-in-place becomes a corrupt-in-place.