Strange error (COBOL)

Hey, I have one problem here. I finished the program that I had to do for homework in college, but when I start it, the output shows almost nothing to suggest. This only happens when I WORK. If I hold F11 to STEP through it all, it will show the results as it should be. Usually I didn’t ask about something so big, but I’m at a dead end. Here is my code:

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SALESAMT-FILE-IN ASSIGN TO 'SALESAMT.SEQ' ORGANIZATION IS LINE SEQUENTIAL. SELECT SALESMAN-FILE-IN ASSIGN TO 'SALESMAN.SEQ' ORGANIZATION IS LINE SEQUENTIAL. SELECT SALESQTR-FILE-IN ASSIGN TO 'SALESQTR.SEQ' ORGANIZATION IS LINE SEQUENTIAL. SELECT SALESAMT-FILE-OUT ASSIGN TO 'SALESAMT.RPT' ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD SALESMAN-FILE-IN. 01 SALESMAN-RECORD-IN. 05 SM-NUMBER-IN PIC 99. 05 SM-NAME-IN PIC X(20). FD SALESQTR-FILE-IN. 01 SALESQTR-RECORD-IN. 05 QUARTER-YEAR PIC X. FD SALESAMT-FILE-IN. 01 SALESAMT-RECORD-IN. 05 SM-NUMBER PIC 99. 05 PIC X. 05 MONTH-NUMBER PIC 9. 05 PIC X. 05 SALES-AMOUNT PIC 9(5). FD SALESAMT-FILE-OUT. 01 SALESAMT-RECORD-OUT PIC X(80). WORKING-STORAGE SECTION. 01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'. 01 REPORT-START PIC X VALUE 'Y'. 01 LINE-COUNT PIC 99 VALUE ZEROS. 01 LINE-JUMP PIC X VALUE 'Y'. 01 PAGE-NUMBER PIC 99 VALUE ZEROS. 01 QUARTER-CHECK PIC X. 01 ROUTINE-CHECK PIC 99 VALUE ZEROS. 01 SALESMAN-MATH PIC 9(5) VALUE ZEROS. 01 SALESMAN-TOTAL PIC 9(6) VALUE ZEROS. 01 FINAL-M-TOTAL-1 PIC 9(7) VALUE ZEROS. 01 FINAL-M-TOTAL-3 PIC 9(7) VALUE ZEROS. 01 FINAL-M-TOTAL-2 PIC 9(7) VALUE ZEROS. 01 FINAL-TOTAL PIC 9(7) VALUE ZEROS. 01 SM-NUM-M PIC 99 VALUE ZEROS. 01 MORE-TABLE-RECS PIC X VALUE 'Y'. 01 SPACE-LINE PIC X VALUE SPACE. 01 MONTH-NAMES VALUE 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'. 05 MONTH-TITLES OCCURS 12 TIMES PIC X(3). 01 MONTH-ARRAY. 05 THREE-MONTHS OCCURS 3 TIMES. 10 MONTH-TOTAL OCCURS 99 TIMES PIC 9(7) VALUE ZEROS. 01 SALESMAN-TABLE. 05 TABLE-ENTRIES OCCURS 99 TIMES INDEXED BY IND-TABLE-ENTRIES. 10 SALESMAN-NUMBER PIC 99 VALUE ZEROS. 10 SALESMAN-NAME PIC X(20) VALUE SPACES. 01 SALESMAN-COUNT PIC 9(3) VALUE ZEROS. 01 WS-DATE. 05 RUN-YEAR PIC XX. 05 RUN-MONTH PIC XX. 05 RUN-DAY PIC XX. 01 HEADING-LINE-1. 05 PIC X(17) VALUE SPACES. 05 PIC X(35) VALUE 'SALES AMOUNTS BY SALESMAN AND MONTH'. 05 PIC X(10) VALUE SPACES. 05 HL-1-DATE. 10 MONTH-2 PIC XX. 10 PIC X VALUE '/'. 10 DAY-2 PIC XX. 10 PIC X VALUE '/'. 10 YEAR-2 PIC XX. 05 PIC X(3) VALUE SPACES. 05 PAGE-1 PIC X(4) VALUE 'PAGE'. 05 PIC X(1) VALUE SPACES. 05 NUMBER-PAGE PIC Z9. 01 HEADING-LINE-2. 05 HL-NUM PIC X(3) VALUE 'NUM'. 05 HL-BLANK-A PIC XX VALUE SPACES. 05 HL-NAME PIC X(4) VALUE 'NAME'. 05 HL-BLANK-B PIC X(20) VALUE SPACES. 05 HL-MONTH-1 PIC X(3) VALUE SPACES. 05 HL-BLANK-C PIC X(8) VALUE SPACES. 05 HL-MONTH-2 PIC X(3) VALUE SPACES. 05 HL-BLANK-D PIC X(8) VALUE SPACES. 05 HL-MONTH-3 PIC X(3) VALUE SPACES. 05 HL-BLANK-E PIC X(10) VALUE SPACES. 05 HL-TOTAL PIC X(5) VALUE 'TOTAL'. 01 DETAIL-LINE. 05 DL-BLANK-A PIC X VALUE SPACES. 05 DL-NUM-COLUMN PIC 99. 05 DL-BLANK-B PIC XX VALUE SPACES. 05 DL-NAME-COLUMN PIC X(17). 05 DL-BLANK-C PIC X(4) VALUE SPACES. 05 DL-MONTH-1 PIC ZZ,Z(3). 05 DL-BLANK-D PIC X(5) VALUE SPACES. 05 DL-MONTH-2 PIC ZZ,Z(3). 05 DL-BLANK-E PIC X(5) VALUE SPACES. 05 DL-MONTH-3 PIC ZZ,Z(3). 05 DL-BLANK-F PIC X(8) VALUE SPACES. 05 DL-TOTAL PIC Z(3),Z(3). 01 TOTALS-LINE. 05 TL-WORDS PIC X(12) VALUE 'Final Totals'. 05 TL-BLANK-A PIC X(12) VALUE SPACES. 05 MONTH-1-TOTAL PIC Z,Z(3),Z(3). 05 TL-BLANK-A PIC X(2) VALUE SPACES. 05 MONTH-2-TOTAL PIC Z,Z(3),Z(3). 05 TL-BLANK-A PIC X(2) VALUE SPACES. 05 MONTH-3-TOTAL PIC Z,Z(3),Z(3). 05 TL-BLANK-A PIC X(5) VALUE SPACES. 05 MONTH-FINAL-TOTAL PIC Z,Z(3),Z(3). PROCEDURE DIVISION. 100-MAIN. OPEN INPUT SALESAMT-FILE-IN, SALESMAN-FILE-IN, SALESQTR-FILE-IN OPEN OUTPUT SALESAMT-FILE-OUT ACCEPT WS-DATE FROM DATE MOVE RUN-MONTH TO MONTH-2 MOVE RUN-DAY TO DAY-2 MOVE RUN-YEAR TO YEAR-2 PERFORM 200-NEXT-PAGE PERFORM 300-SALES-ARRAY PERFORM 400-SALESMAN-NAME PERFORM 500-PROCESS-FILE PERFORM 600-FINAL-TOTALS CLOSE SALESAMT-FILE-IN, SALESMAN-FILE-IN, SALESQTR-FILE-IN CLOSE SALESAMT-FILE-OUT STOP RUN. 200-NEXT-PAGE. ADD 1 TO PAGE-NUMBER MOVE PAGE-NUMBER TO NUMBER-PAGE MOVE HEADING-LINE-1 TO SALESAMT-RECORD-OUT IF REPORT-START = 'N' WRITE SALESAMT-RECORD-OUT AFTER ADVANCING PAGE ELSE MOVE 'N' TO REPORT-START WRITE SALESAMT-RECORD-OUT AFTER ADVANCING 1 LINE PERFORM 210-MONTH-CHECK END-IF. MOVE HEADING-LINE-2 TO SALESAMT-RECORD-OUT WRITE SALESAMT-RECORD-OUT AFTER ADVANCING 2 LINES MOVE ZEROS TO LINE-COUNT. 210-MONTH-CHECK. READ SALESQTR-FILE-IN AT END CONTINUE NOT AT END PERFORM 220-MONTH-NAME END-READ. 220-MONTH-NAME. EVALUATE QUARTER-YEAR WHEN = 1 MOVE MONTH-TITLES(1) TO HL-MONTH-1 MOVE MONTH-TITLES(2) TO HL-MONTH-2 MOVE MONTH-TITLES(3) TO HL-MONTH-3 WHEN = 2 MOVE MONTH-TITLES(4) TO HL-MONTH-1 MOVE MONTH-TITLES(5) TO HL-MONTH-2 MOVE MONTH-TITLES(6) TO HL-MONTH-3 WHEN = 3 MOVE MONTH-TITLES(7) TO HL-MONTH-1 MOVE MONTH-TITLES(8) TO HL-MONTH-2 MOVE MONTH-TITLES(9) TO HL-MONTH-3 WHEN = 4 MOVE MONTH-TITLES(10) TO HL-MONTH-1 MOVE MONTH-TITLES(11) TO HL-MONTH-2 MOVE MONTH-TITLES(12) TO HL-MONTH-3 END-EVALUATE. 300-SALES-ARRAY. PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO ' READ SALESAMT-FILE-IN AT END MOVE 'NO ' TO ARE-THERE-MORE-RECORDS NOT AT END PERFORM 310-STORE-DATA END-READ END-PERFORM. 310-STORE-DATA. MOVE SM-NUMBER TO SM-NUM-M EVALUATE MONTH-NUMBER WHEN 1 PERFORM 320-FIRST-MONTH WHEN 2 PERFORM 330-SECOND-MONTH WHEN 3 PERFORM 340-THIRD-MONTH END-EVALUATE. 320-FIRST-MONTH. ADD SALES-AMOUNT TO MONTH-TOTAL OF MONTH-ARRAY (1, SM-NUM-M). 330-SECOND-MONTH. ADD SALES-AMOUNT TO MONTH-TOTAL OF MONTH-ARRAY (2, SM-NUM-M). 340-THIRD-MONTH. ADD SALES-AMOUNT TO MONTH-TOTAL OF MONTH-ARRAY (3, SM-NUM-M). 400-SALESMAN-NAME. PERFORM UNTIL MORE-TABLE-RECS = 'N' READ SALESMAN-FILE-IN AT END MOVE 'N' TO MORE-TABLE-RECS NOT AT END PERFORM 450-TABLE-LOAD END-READ END-PERFORM. 450-TABLE-LOAD. MOVE SM-NUMBER-IN TO SALESMAN-COUNT MOVE SM-NUMBER-IN TO SALESMAN-NUMBER (SALESMAN-COUNT) MOVE SM-NAME-IN TO SALESMAN-NAME (SALESMAN-COUNT). 500-PROCESS-FILE. PERFORM UNTIL ROUTINE-CHECK = 99 ADD 1 TO ROUTINE-CHECK PERFORM 510-TABLE-SEARCH END-PERFORM. 510-TABLE-SEARCH. SEARCH TABLE-ENTRIES WHEN SALESMAN-NUMBER (ROUTINE-CHECK) = ROUTINE-CHECK PERFORM 520-WRITE-FILE WHEN SALESMAN-NUMBER (ROUTINE-CHECK) = 0 CONTINUE END-SEARCH. 520-WRITE-FILE. MOVE SALESMAN-NAME (ROUTINE-CHECK) TO DL-NAME-COLUMN IF DL-NAME-COLUMN = SPACES MOVE '*** Not Found ***' TO DL-NAME-COLUMN END-IF MOVE ROUTINE-CHECK TO DL-NUM-COLUMN MOVE ROUTINE-CHECK TO SM-NUM-M MOVE MONTH-TOTAL (1, SM-NUM-M) TO DL-MONTH-1 MOVE DL-MONTH-1 TO SALESMAN-MATH ADD SALESMAN-MATH TO SALESMAN-TOTAL ADD SALESMAN-MATH TO FINAL-M-TOTAL-1 ADD SALESMAN-MATH TO FINAL-TOTAL MOVE MONTH-TOTAL (2, SM-NUM-M) TO DL-MONTH-2 MOVE DL-MONTH-2 TO SALESMAN-MATH ADD SALESMAN-MATH TO SALESMAN-TOTAL ADD SALESMAN-MATH TO FINAL-M-TOTAL-2 ADD SALESMAN-MATH TO FINAL-TOTAL MOVE MONTH-TOTAL (3, SM-NUM-M) TO DL-MONTH-3 MOVE DL-MONTH-3 TO SALESMAN-MATH ADD SALESMAN-MATH TO SALESMAN-TOTAL ADD SALESMAN-MATH TO FINAL-M-TOTAL-3 ADD SALESMAN-MATH TO FINAL-TOTAL IF SALESMAN-TOTAL > 0 MOVE SALESMAN-TOTAL TO DL-TOTAL MOVE DETAIL-LINE TO SALESAMT-RECORD-OUT WRITE SALESAMT-RECORD-OUT AFTER ADVANCING 2 LINES END-IF MOVE ZEROS TO SALESMAN-TOTAL. 600-FINAL-TOTALS. MOVE FINAL-M-TOTAL-1 TO MONTH-1-TOTAL MOVE FINAL-M-TOTAL-2 TO MONTH-2-TOTAL MOVE FINAL-M-TOTAL-3 TO MONTH-3-TOTAL MOVE FINAL-TOTAL TO MONTH-FINAL-TOTAL MOVE TOTALS-LINE TO SALESAMT-RECORD-OUT WRITE SALESAMT-RECORD-OUT AFTER ADVANCING 3 LINES. 

It seems to me that the logic is correct, since it works, but for some reason it (in my opinion, when I see the results) completely jumps over the 520-WRITE-FILE when it works. However, I leave a few notes.

  • I know that 510-TABLE-SEARCH does not make sense, and I intend to change it later, but I need to fix it first, and it works at the moment. If this is not the main problem, do not bother me.

  • I want to add data to SEQ files if someone asks me about it.

  • My code can be a little complicated, and I agree with that, but I am doing everything in my power with the teacher I have (basically I have to study this material myself).

    / li>

I appreciate any help I receive and thank anyone who tries to help in advance.

edit: I use a compiler called Micro Focus, Net Express 5.1 Academic Edition, and my OS is Windows Vista. As for what the program shows, when I start it, it just shows my two header lines and then my summary line, but nothing but the first field. Hope this helps.

+7
source share
5 answers

I do not know for sure if this is a problem, but I see a logical stream that will not work very well ...

First: 400-SALESMAN-NAME reads seller records from a file into the SALESMAN-TABLE storage SALESMAN-TABLE .

The file probably looks something like this:

 01Sales Guy One 02Lance Winslow 03Scott Peterson 04Willy Loman 

When the read loop is completed, SALESMAN-NUMBER will be equal to the index of the table due to how you load the table (using SM-NUMBER-IN to set the index of the table). Not a problem yet ...

Next: 500-PROCESS-FILE scrolls all the lines in SALESMAN-TABLE by running the ROUTINE-CHECK index from 1 to 99 and executing 510-TABLE-SEARCH to write a report for the seller, where the index is SALESMAN-NUMBER ...

Next: the SEARCH statement. Everything here is strange and never performs 520-WRITE-FILE . That's why.

The SEARCH operator implements a linear search ( SEARCH ALL - binary search). SEARCH simply increments the index associated with the table you are looking for and then goes through the WHEN test suite until one of them fries or the index expires from the end of the table. The index for your TABLE-ENTRIES is IND-TABLE-ENTRIES . But you never install or refer to it (this is the root of the problem). I will explain in a moment ...

Note that the WHEN part of your SEARCH uses the ROUTINE-CHECK index. ROUTINE-CHECK was set to 500-PROCESS-FILE . Also note that you only get 520-WRITE-FILE if SALESMAN-NUMBER matches the ROUTINE-CHECK value - which it will do if the seller from this number was read from the input file. This might work because you loaded the table so that the line number was equal to the seller number in 450-TABLE-LOAD .

Now, what happens if the input file does not contain a seller, where SM-NUMBER-IN is 01?

Pass through it, strike a blow ...

ROUTINE-CHECK set to 1, SEARCH is also called because the IND-TABLE-ENTRIES associated with the found table is less than the number found in the table (it was initialized to zero when the program was loaded). WHEN are WHEN .

The first test is WHEN SALESMAN-NUMBER (ROUTINE-CHECK) = ROUTINE-CHECK . Since Salesman 1 does not exist, SALESMAN-NUMBER will be zero and the test will fail (0 <> 1).

The following WHEN clause is checked, and it succeeds because (0 = 0); but this is the "do nothing" option, so another SEARCH loop is introduced after IND-TABLE-ENTRIES incremented .

The same results and all subsequent iterations through the SEARCH ed WHEN list (none of the sentences match) ... Repeat this cycle until IND-TABLE-ENTRIES is expanded outside the table.

At this point, the SEARCH terminates and control returns to the next cycle in the 500-PROCESS-FILE . Nothing was printed.

500-PROCESS-FILE then increments ROUTINE-CHECK by 1 (now 2). We have a seller with SALESMAN-NUMBER of 02, so we should get some result - right? Wrong! But why?

If you read the verb SEARCH , you will find that it does not reset the table index (in this case: IND-TABLE-ENTRIES ). He begins to use whatever value he has when entering SEARCH. You never reset, so it is already installed outside the table. The SEARCH just ends and nothing is printed - again and again.

Problem fixing

Given that you downloaded TABLE-ENTRIES by seller number in the first place, I don’t see the purpose of using SEARCH. Just do something like:

 500-PROCESS-FILE. PERFORM VARYING ROUTINE-CHECK FROM 1 BY 1 UNTIL ROUTINE-CHECK > 99 IF SALESMAN-NUMBER (ROUTINE-CHECK) = ZERO CONTINUE ELSE PERFORM 520-WRITE-FILE END-IF END-PERFORM. 

It would also be nice to have an initialization cycle for the table so that each SALESMAN-NUMBER is explicitly set to zero before reading the seller file.

If you must use SEARCH in this program, be sure to set and use the associated table index variable when referencing a regular table.

+4
source

I added this as a second answer, which I think is right!

520-WRITE-FILE is not executed because the SEARCH to call it does not work.

In 510-TABLE-SEARCH, I find you need to search by the index declared for the table, IND TABLE-RECORD. You will probably need to transcode 500-PROCESS-FILE and 510-TABLE-SEARCH.

In another question, you asked about the verb SEARCH. fmartin gave a link describing how this works with examples.

+1
source

Pls. Change to this:

  SELECT SALESAMT-FILE-OUT ASSIGN TO 'SALESAMT.RPT' ORGANIZATION IS LINE SEQUENTIAL File Status is FILESTATUS. 

And add this:

01 FILESTATUS.

  02 FILESTATUS-1 Pic 9. 88 SUCCESSFULL Value 0. 88 END-OF-FILE Value 1. 88 INVALID-KEY Value 2. 88 PERMANENT-ERROR Value 3, 9. 02 FILESTATUS-2 Pic 9. 88 DUPLICATE-KEY Value 2. 88 NO-RECORD-FOUND Value 3. 88 FILE-IS-FULL Value 4. 

Check FILESTATUS every time you do something with SALESAMT-FILE-OUT. (you can also do with other files). With this modification, u will be able to see if there is any error when u is doing IO.

This is the first step, so this is not the final question regarding the privacy issue.

0
source

"it just shows my two header lines and then my summary line"

In your paragraph 520-WRITE-FILE you have the following code

 IF SALESMAN-TOTAL > 0 MOVE SALESMAN-TOTAL TO DL-TOTAL MOVE DETAIL-LINE TO SALESAMT-RECORD-OUT WRITE SALESAMT-RECORD-OUT AFTER ADVANCING 2 LINES END-IF 

If SALESMAN-TOTAL is zero, your program will not print verbose lines. It looks like you have data or a logical error in the sum of SALESMAN-TOTAL.

0
source

I think you have a pretty simple problem with your current working directory.

In the environment unit, you declare file descriptors and assign them to file names.

When debugging a program, the input files are located in your current working directory and therefore are correctly resolved.

When you run the program, I assume that you are running it from another directory, so the input files are not allowed, so the output file contains only one header line.

0
source

All Articles